将NSInteger转换为NSIndexpath

Dan*_*Dan 38 objective-c nsinteger nsindexpath ios

基本上我在NSInteger中存储数组的索引.我现在需要它作为NSIndexpath,我很难看到并找到一种方法将我的NSInteger转换为NSIndexpath,所以我可以重用它.

age*_*ped 89

对于int index:

NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];
Run Code Online (Sandbox Code Playgroud)

创建节点0中项目的索引以指向根据引用.

要在a中使用indexPath UITableView,更合适的方法是

NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section];
Run Code Online (Sandbox Code Playgroud)


alb*_*amg 8

如果你需要NSIndexPathUITableView,你可以使用indexPathForRow:inSection:(参考).传递给表视图的索引路径必须包含指定节和行的两个索引.创建的索引路径indexPathWithIndex:仅包含一个索引,不适用于表视图.