gpt4 book ai didi

ios - 如何检测 UITableViewCells 之外的 UITableView 上的点击 - 即在部分标题中?

转载 作者:可可西里 更新时间:2023-11-01 03:39:14 28 4
gpt4 key购买 nike

我想在不包括单元格的 UITableView 中处理点击。换句话说,页眉和页脚。

我可以向页眉添加手势识别器(没有页脚),但最后一部分底部的空间不响应点击。

我没有在上面添加手势识别器,而是尝试向表中添加手势识别器,但它阻止了 tableView:didSelectRowAtIndexPath: 被调用。

我尝试了各种 UIGestureRecognizerDelegate 调用,但运气不佳。

我终于通过在识别器上设置 cancelsTouchesInView = NO(我认为这是 secret )并在委托(delegate)中实现 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 来实现它,这样tableView 得到触摸并调用 tableView:didSelectRowAtIndexPath:

处理程序必须过滤掉单元格上的点击,但至少它可以工作。 (此外,在 UITableView indexPathForRowAtPoint:point 中发现了一个错误,它有时会返回无效的 indexPaths。)

我的问题是:是否有更好的方法来获取单元格 View 以防止触摸/手势到达表格? (如果没有人给我更好的想法,我会发布代码。)

最佳答案

如果您不需要理解-点击了什么(页脚或页眉),您可以尝试以下方法。

viewDidLoad 方法中添加手势识别器。

- (void) tableViewLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self.tableView];

NSIndexPath *indexPath = [self.messageTableView indexPathForRowAtPoint:p];
if (indexPath == nil)
NSLog(@"long press on table view but not on a row");
else {
NSLog(@"long press on table view on a row");
}
}

注意!我还没有测试过这段代码:)

关于ios - 如何检测 UITableViewCells 之外的 UITableView 上的点击 - 即在部分标题中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24926279/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com