ios - 手动调用 didSelectRowAtIndexPath 时出现异常

标签 ios objective-c uitableview nsindexpath

我正在尝试在 UITableview 上手动调用 didSelectRowAtIndexPath。这样做时出现以下异常:

'Invalid index path for use with UITableView.  Index paths passed to table view must contain exactly two indices specifying the section and row.

这是导致异常的代码:

-(void)refreshLayerAtIndexPath:(NSUInteger)index {
    NSIndexPath* indexPath = [[NSIndexPath alloc] initWithIndex:index];
    [self tableView:_tableViewLayers didSelectRowAtIndexPath:indexPath];
}

我看不到任何地方可以明确设置该部分。

有什么建议吗?谢谢!

最佳答案

使用 UITableView 还需要指定 NSIndexPath 的部分

NSIndexPath* indexPath = [NSIndexPath indexPathForRow:row inSection:section];

关于ios - 手动调用 didSelectRowAtIndexPath 时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30515741/

相关文章:

ios - 如何在 AsyncDisplayKit ASButtonNode 上设置标题?

ios - YouTube API : clang: error: linker command failed with exit code 1 (use -v to see invocation)

ios - 如何从多个 Realm 模型创建一个 tableview?

ios - 加载了 Nib 但没有得到 UITableView

ios - tableView header透明背景变黑色

c# - 清除 WebView 缓存 xamarin IOS

ios - KeyPress 上的 UISearchbar 触发方法

ios - 在PFQueryTableViewController中删除单元格和[self loadObjects]时,它在-[UITableView _endCellAnimationsWithContext:]中出现断言失败。

iphone - CoreData 有什么不同

objective-c - 返回函数的函数