【发布时间】:2014-04-20 20:31:20
【问题描述】:
经过漫长但徒劳的搜索,我无法在我的 tableview 中检测到双击/触摸事件,实际上想在任何 TableViewCell 上调用双击时的详细视图,实际上我什至没有完全知道该怎么做。
这是我目前的代码……
在 viewDidLoad
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[self.myTable addGestureRecognizer:tapGesture];
handleTapGesture方法是
- (void)handleTapGesture:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateRecognized) {
flag = true;
}
}
最后触摸或点击 tableview 的单元格 委托方法是
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (flag == true)
{
DetailInvoicing *detail = [[DetailInvoicing alloc] initWithNibName:@"DetailInvoicing" bundle:nil];
detail.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
detail.customerName = [customerArray objectAtIndex:indexPath.row];
[self presentViewController:detail animated:YES completion:nil];
}
}
如果我删除此标志条件,只需单击一下即可调用新视图。 我在哪里错了,或者还有其他方法吗。
【问题讨论】:
-
请将
flag = true;替换为flag = YES;并将flag == true替换为flag。 -
你可以参考这个链接,希望你的问题能得到解决。 stackoverflow.com/questions/1031254/…谢谢
-
为什么不在您检测到双击的位置显示视图(在 handleTapGesture 中)?
-
@nhgrif 它可以工作,但不是特别在双击时……当我双击时什么也没发生,然后它在第三次和第四次点击时调用了新视图……
-
@Anna 我必须将单元格值发送到新视图,这就是为什么使用这种方式
标签: ios iphone objective-c uitableview