Ios 可点击UILabel

Ios 可点击UILabel,ios,objective-c,iphone,uigesturerecognizer,Ios,Objective C,Iphone,Uigesturerecognizer,我正在尝试制作一个UILabel,如果我单击它,我可以编辑它。我有一个隐藏的文本字段 根据这一回答: 我尝试了以下方法: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. tapInput = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(didTap

我正在尝试制作一个UILabel,如果我单击它,我可以编辑它。我有一个隐藏的文本字段

根据这一回答:

我尝试了以下方法:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    tapInput = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(didTapLabel)];
    [lblInput setUserInteractionEnabled:YES];
    [lblInput addGestureRecognizer:tapInput];
}

-(void)didTapLabel
{
    [txtHidden becomeFirstResponder];
}

但我在didTapLabel内的断点没有开火。故事板上的所有内容都已正确连接。

请尝试在此处为label启用用户交互,这对我很有用,请使用UIApsigner而不是UISigner Textfield应该在uilabel下面,因为如果Textfield在label上面,那么uilabel的用户交互就不会被考虑


请尝试在此处为label启用用户交互,这对我来说很有用,请使用UIApsignature而不是UISignature Textfield应该在uilabel下面,因为如果Textfield在label上面,那么uilabel的用户交互就不会被考虑


使用此代码,它可以正常工作。测试

UILabel * clickMeLbl=[[UILabel alloc] initWithFrame:CGRectMake(75,30,170,30)];
clickMeLbl.text = @"Click Me";
clickMeLbl.font = [UIFont fontWithName:@"Helvetica-Bold" size: 18.0f ];
clickMeLbl.textAlignment =  NSTextAlignmentCenter;
clickMeLbl.textColor = [UIColor blackColor];
[self.view addSubview:clickMeLbl];

clickMeLbl.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapLabelWithGesture:)];
[clickMeLbl addGestureRecognizer:tapGesture];


- (void)didTapLabelWithGesture:(UITapGestureRecognizer *)tapGesture {
   NSLog(@"Click Me Label Clicked");
}

使用这个代码,它是有效的。测试

UILabel * clickMeLbl=[[UILabel alloc] initWithFrame:CGRectMake(75,30,170,30)];
clickMeLbl.text = @"Click Me";
clickMeLbl.font = [UIFont fontWithName:@"Helvetica-Bold" size: 18.0f ];
clickMeLbl.textAlignment =  NSTextAlignmentCenter;
clickMeLbl.textColor = [UIColor blackColor];
[self.view addSubview:clickMeLbl];

clickMeLbl.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapLabelWithGesture:)];
[clickMeLbl addGestureRecognizer:tapGesture];


- (void)didTapLabelWithGesture:(UITapGestureRecognizer *)tapGesture {
   NSLog(@"Click Me Label Clicked");
}

uitagesturerecognizer
vs
UIGestureRecognizer
UIGestureRecognizer
非常“通用”,并且您没有设置任何所需的点击次数,等等……您是否考虑过仅使用UITextField并在其上执行isUserInteractionEnabled=false和endEditing:以使其不可编辑?
UIGestureRecognizer
vs
UIGestureRecognizer
UIGestureRecognitizer
非常“通用”,并且您没有设置任何所需的点击次数,等等。您是否考虑过仅使用UITextField并对其执行isUserInteractionEnabled=false和endEditing:以使其不可编辑?您是否检查了此答案@乔希:是的,谢谢!我的问题是我没有使用TapGestureRecognitor。谢谢你的帮助!你核对过这个答案了吗@乔希:是的,谢谢!我的问题是我没有使用TapGestureRecognitor。谢谢你的帮助!