- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 View 加载中,我有两个 UILabel,并且我为两者添加了相同的 tapGesture。如果点击特定标签,则应该执行其功能。但我无法这样做?
-(void)viewDidLoad{
lblEditProfile.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClicked:)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
[lblEditProfile addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
lblViewDetails.userInteractionEnabled = YES;
tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClicked:)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
[lblViewDetails addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
}
-(IBAction)labelClicked:(UITapGestureRecognizer*)tapGestureRecognizer
{
currentLabel = (UILabel *)tapGestureRecognizer.view;
NSLog(@"tap %@",tapGestureRecognizer.view);
if(currentLabel.text==@"Edit Profile")
{
UserProfile *userProfile = [[UserProfile alloc] initWithNibName:@"UserProfile" bundle:nil];
userProfile.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:userProfile animated:YES];
[userProfile release];
}
else
{
ViewDetails *viewDetails = [[ViewDetails alloc] initWithNibName:@"UserAppointments" bundle:nil];
viewDetails.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: viewDetails animated:YES];
[viewDetails release];
}
}
但是当我单击 EditProfile 标签时,它会被阻止。
如何识别哪个标签被点击并相应地执行所需的操作?
最佳答案
使用这样的标签格式。哪个会更有效率
-(void)viewDidLoad{
lblEditProfile.userInteractionEnabled = YES;
lblEditProfile.tag = 1;
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClicked:)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
[lblEditProfile addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
lblViewDetails.userInteractionEnabled = YES;
lblViewDetails.tag = 2;
tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClicked:)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
[lblViewDetails addGestureRecognizer:tapGestureRecognizer];
[tapGestureRecognizer release];
}
-(IBAction)labelClicked:(UITapGestureRecognizer*)tapGestureRecognizer
{
currentLabel = (UILabel *)tapGestureRecognizer.view;
NSLog(@"tap %d",tapGestureRecognizer.tag);
if(currentLabel.tag == 1)
{
UserProfile *userProfile = [[UserProfile alloc] initWithNibName:@"UserProfile" bundle:nil];
userProfile.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:userProfile animated:YES];
[userProfile release];
}
else if(currentLabel.tag == 2)
{
ViewDetails *viewDetails = [[ViewDetails alloc] initWithNibName:@"UserAppointments" bundle:nil];
viewDetails.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: viewDetails animated:YES];
[viewDetails release];
}
}
关于iphone - 识别 UITapGestureRecogniser 的多个 UILabels 点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14081466/
我有一个objc函数: @objc private func segmentedControlViewTapped(gestureRecognizer: UITapGestureRecognizer)
我在 UITableViewCell 中有一个 UILabel,它显示电话号码。当我单击它时,我应该能够调用该特定号码。因此,为了使其可点击,我向其中添加了一个 UITapGestureRecogni
我正在使用 swift 创建一个应用程序。在我的一个 ViewController 中,我有一个以编程方式创建的 GMSMapView。我希望用户能够在点击 map 时触发操作。 我做了什么: imp
在我的 View 加载中,我有两个 UILabel,并且我为两者添加了相同的 tapGesture。如果点击特定标签,则应该执行其功能。但我无法这样做? -(void)viewDidLoad{ l
我正在尝试将相同的 UITapGestureRecognizer 添加到多个 View 中作为 var tapGesture = UITapGestureRecognizer(target: se
我是一名优秀的程序员,十分优秀!