gpt4 book ai didi

iphone - UITableView 查找部分标题的位置?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:52:53 26 4
gpt4 key购买 nike

我试图找出在 tableview 上滑动时 swipeGesture 的位置。在滑动 Action 中,我见过很多人这样做:

CGPoint location = [recognizer locationInView:tableView];
NSIndexPath* indexPath = [tableView indexPathForRowAtPoint:location];
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];

但我的 tableView 由其中没有单元格的节标题组成。因此,索引路径方法返回 nil。有没有办法找到Section header的位置?他们没有这种方法,但像 indexPathForSectionAtPoint: 这样的东西就是我要找的东西。如果有人知道如何执行此操作,将不胜感激。

谢谢,

最佳答案

您已经有了locationindexPath
现在,要获取您使用 indexPath.row 的单元格(及其数据),如您的示例所示。
要获取部分(有或没有单元格),您可以使用 indexPath.section

如果点 location 下没有行 indexPathForRowAtPoint: 将返回 nil,这是预期的行为。

章节标题并不是真正意义上的交互 View 区域。相反,它们是标题。 UITableView 旨在响应与其行的交互。

也许解决此问题的一种方法是更改​​您的数据结构,以便您在章节标题中显示的内容真正存在于表格 View 行中。

另一种方法是使用节标题的 UIView 并让它响应滑动手势。 (确保使用 super 将手势传递到 TableView 。)

关于iphone - UITableView 查找部分标题的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9759364/

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