gpt4 book ai didi

ios - UITableView indexPathForSelectedRow 在 iOS 中总是返回 0

转载 作者:行者123 更新时间:2023-12-01 18:20:15 26 4
gpt4 key购买 nike

我需要获取 UITableView 的索引与 UILongPressGestureRecognizer在 iOS 中。

首先我添加了UILongPressGestureRecognizer并使用以下代码检索选定行的索引路径。

- (void)handleLongPress : (UILongPressGestureRecognizer *)ges
{
NSIndexPath *indexPath = [self.tblMainTableView indexPathForSelectedRow];
NSLog(@"%i",indexPath.row);
}

当我点击 UITableView 的第三行时, 它只返回 0并始终返回 0无论我在哪里点击 tableView。

如何使用 UILongPressGestureRecognizer 获取索引 TableView ?

感谢您的任何建议和帮助。

最佳答案

-(void)handleLongPress:(UILongPressGestureRecognizer *)ges
{
CGPoint touch = [ges locationInView:self.tblMainTableView];

NSIndexPath *indexPath = [self.tblMainTableView indexPathForRowAtPoint:touch];

}

使用 tableView 上的触摸点通过 indexPathForRowAtPoint 访问行方法

关于ios - UITableView indexPathForSelectedRow 在 iOS 中总是返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17817866/

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