我有一个数据情况,我想使用索引路径.当我遍历数据时,我想增加NSIndexPath的最后一个节点.我到目前为止的代码是:
int nbrIndex = [indexPath length]; NSUInteger *indexArray = (NSUInteger *)calloc(sizeof(NSUInteger),nbrIndex); [indexPath getIndexes:indexArray]; indexArray[nbrIndex - 1]++; [indexPath release]; indexPath = [[NSIndexPath alloc] initWithIndexes:indexArray length:nbrIndex]; free(indexArray);
这感觉有点,嗯,笨重 – 有更好的方法吗?
解决方法
你可以尝试这个 – 也许同样笨重,但至少有点短:
NSInteger newLast = [indexPath indexAtPosition:indexPath.length-1]+1; indexPath = [[indexPath indexPathByRemovingLastIndex] indexPathByAddingIndex:newLast];