创建具有一个或多个节点的索引路径的类方法是:
+ (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length
我们如何创建第一个参数中所需的“索引”?
文档将其列为索引数组以构成索引路径,但它需要一个 (NSUinteger *)。
要创建 1.2.3.4 的索引路径,是否只是 [1,2,3,4] 的数组?
创建具有一个或多个节点的索引路径的类方法是:
+ (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length
我们如何创建第一个参数中所需的“索引”?
文档将其列为索引数组以构成索引路径,但它需要一个 (NSUinteger *)。
要创建 1.2.3.4 的索引路径,是否只是 [1,2,3,4] 的数组?
你是对的。你可以这样使用它:
NSUInteger indexArr[] = {1,2,3,4};
NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:indexArr length:4];
在 iOS 上,您还可以使用NSIndexPath UIKit Additions中的此方法(在 UITableView.h 中声明):
+ (NSIndexPath*) indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section
你的假设是正确的。它就像 NSUInteger 的 C 数组一样简单。length 参数是索引数组中元素的数量。
C 中的数组通常被标识为带有长度参数的指针(在本例中为 NSUInteger *)或已知的终止符,例如 C 字符串的 \0(它只是一个 char 数组)。
我用两行代码做到了这一点
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
for (int i = firstIndexYouWant; i < totalIndexPathsYouWant; i++) [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
简短、干净、易读。免费代码,不要敲它。