我正在尝试处理某些操作,当用户使用以下代码点击UITextField
内的UItableView
但未调用tapDetected:
代码时。
UITableViewCell *cell = [[UITableViewCell alloc] init];
UITextField *txtComment=[[UITextField alloc]initWithFrame:CGRectMake(10, 10,cell.contentView.frame.size.width-30 , 30)];
[txtComment setText:NSLocalizedString(@"Comment Here", nil)];
[txtComment setFont:mediumFont];
[txtComment setTintColor:[UIColor grayColor]];
[txtComment setTag:newCommentTag];
txtComment.layer.masksToBounds=YES;
txtComment.layer.borderColor=[[UIColor lightGrayColor]CGColor];
txtComment.layer.borderWidth= 0.3f;
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(tapDetected:)];
tap.numberOfTapsRequired = 1;
[txtComment addGestureRecognizer:tap];
[cell.contentView addSubview:txtComment];
- (IBAction)tapDetected:(UIGestureRecognizer *)sender
{
[[NSNotificationCenter defaultCenter] postNotificationName:spAddNewCommentNotification object:nil];
}
答案 0 :(得分:1)
你可以继承你自己的UITableViewCell并将触摸检测放在里面。
答案 1 :(得分:0)
我认为当你触摸那个时间UITableViewdidSelect
时会调用委托方法。所以请遵循以下代码:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isDescendantOfView:cell])
{
return NO;
}
return YES;
}
试试这个。我认为这可以帮助你:)