基本上我将数组的索引存储在 NSInteger 中。我现在需要它作为 NSIndexpath,我正在努力寻找并找到一种将我的 NSInteger 转换为 NSIndexpath 的方法,以便我可以重用它。
问问题
39289 次
4 回答
90
对于一个 int index
:
NSIndexPath *path = [NSIndexPath indexPathWithIndex:index];
要在 a 中使用 indexPath UITableView
,更合适的方法是
NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section];
于 2011-06-23T13:27:18.177 回答
8
如果你需要 a NSIndexPath
,UITableView
你可以使用indexPathForRow:inSection:
(参考)。传递给表视图的索引路径必须恰好包含两个指定节和行的索引。创建的索引路径indexPathWithIndex:
仅包含一个索引,不适用于表视图。
于 2011-06-23T14:14:58.383 回答
3
使用以下 NSIndexPath类的方法。
+ (id)indexPathWithIndex:(NSUInteger)index;
+ (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length;
- (id)initWithIndex:(NSUInteger)index
如下使用,使用后也不要忘记release
myIndexPath
反对。
NSIndexPath *myIndexPath = [[NSIndexPath alloc] initWithIndex:[myIntObj intValue]];
于 2011-06-23T13:24:40.070 回答
2
斯威夫特 3:
let indexPath = IndexPath(row: 0, section: 0)
于 2016-10-24T20:56:25.100 回答