为 UITapGestureRecogniser 识别多个 UILabels tap [英] Recognizing multiple UILabels tap for UITapGestureRecogniser
本文介绍了为 UITapGestureRecogniser 识别多个 UILabels tap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的视图加载中,我有两个 UILabel,并且我为两者添加了相同的 tapGesture.如果点击了特定标签,则应执行其功能.但我无法这样做?
In my view load I have two UILabels and I have added same tapGesture for both.If a particular label is tapped then its functionality should be performed.But I m unable to do so ?
-(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 标签时,它会阻止.
But when I click on EditProfile label it is going to else block.
如何识别点击了哪个标签并相应地执行所需操作?
How can I recognize which Label is clicked and correspondingly perform required action?
推荐答案
像这样检查:
if(currentLabel == lblEditProfile)
//code here
else
//code here
这篇关于为 UITapGestureRecogniser 识别多个 UILabels tap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文