加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 识别多个UIL用户点击UITapGestureRecogniser

发布时间:2020-12-14 17:12:13 所属栏目:百科 来源:网络整理
导读:在我的视图加载中我有两个UILabel,我为两者添加了相同的tapGesture.如果点击一个特定的标签,那么应该执行它的功能.但是我无法这样做? -(void)viewDidLoad{ lblEditProfile.userInteractionEnabled = YES; UITapGestureRecognizer *tapGestureRecognizer = [
在我的视图加载中我有两个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标签时,它将转到else块.

如何识别单击哪个标签并相应执行所需操作?

解决方法

像这样检查:

if(currentLabel == lblEditProfile)
    //code here
  else
     //code here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读