【发布时间】:2014-11-04 15:39:11
【问题描述】:
基本上我想要实现的是在自定义 UITableViewCell 中有一个 UITextField ,而这个文本字段应该只在长按时触发。因此,如果用户只是在文本字段上点击一次,则单元格应触发其委托方法 didSelectRow。
到目前为止,我在文本字段上添加了长按并删除了所有其他手势。因此,当我长按它时,我的文本字段会正确触发。但问题是,当我只是点击文本字段时,不会触发单元格并且不会调用 didSelectRow 方法。如果我在我的文本字段之外点击,则该方法被正确地称为 ofc。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.nameTextField.gestureRecognizers = nil;
UILongPressGestureRecognizer *longPressTextField = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleCellTextFieldLongPress:)];
[cell.nameTextField addGestureRecognizer:longPressTextField];
return cell;
}
我用 UIGestureRecognizerDelegate 尝试了不同的东西,但似乎没有一个工作:(。
任何想法表示赞赏!谢谢!
【问题讨论】:
标签: ios objective-c iphone uitableview