ios - 将 NSInteger 转换为 NSIndexpath

标签 ios objective-c nsindexpath nsinteger

基本上,我将数组的索引存储在 NSInteger 中。我现在需要它作为 NSIndexpath,我正在努力寻找并找到一种将我的 NSInteger 转换为 NSIndexpath 的方法,以便我可以重用它。

最佳答案

对于一个 int index:

NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];

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

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

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

关于ios - 将 NSInteger 转换为 NSIndexpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6454723/

相关文章:

ios - 检测用户何时到达设备的左侧或右侧屏幕边缘

ios - 如果 UITextField 密码字段的内容超过特定长度,应用程序会挂起

ios - Swift iOS TableView 单元格项目在滚动时消失

ios - 为什么在 View 上设置背景图片会降低我的 iOS 应用程序的速度?

Swift - UICollectionView reloadItems 花费太长时间

uitableview - 如何单击按钮将 tableview 单元格附件类型重置为无?

ios - 在手势识别器操作方法中更改 `SKNode` 是否安全?

ios - 将 Objective-C 中的函数转换为 swift

ios - 如何使 PFSignupViewController 中的字段之一可选

ios - 如何将 [didSelectRowAtIndexPath] 选中的单元格变成字符串供以后使用