我有一個包含UILabel的單元格的UITableView。當我點擊UILabel時,我想要執行一個動作,因此我添加了一個UITapGestureRecognizer。Objective-c UITapGestureRecognizer無法識別的選擇器
UILabel *telephone = (UILabel *)[cell.contentView viewWithTag:420];
telephone.userInteractionEnabled = YES;
UITapGestureRecognizer *tapToCall = [[UITapGestureRecognizer alloc] initWithTarget:telephone action:@selector(tapToCall:)];
[telephone addGestureRecognizer:tapToCall];
然後我定義的選擇方法:
-(void)tapToCall: (UITapGestureRecognizer*) sender {
UILabel *telephone = (UILabel *) sender.view;
NSLog(@"%@", telephone.text);
}
但現在我收到一個錯誤,當我接觸到的UILabel:
2017-03-07 13:17:49.220 [37354:2794848] -[UILabel tapToCall:]: unrecognized selector sent to instance 0x7fc39f459250
2017-03-07 13:17:49.253 [37354:2794848] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel tapToCall:]: unrecognized selector sent to instance 0x7fc39f459250'
我是怎麼在這裏做錯了嗎?