更改NSIndexPath对象的值

Sta*_*ley 3 iphone cocoa

如果我有一个值为{0,0}的索引路径.将其更改为{0,1}的正确方法是什么?我知道如果它是一个普通的c数组,它只会是:

unsigned i_array[] = { 0, 0};
i_array[1] = 1;
Run Code Online (Sandbox Code Playgroud)

但是从NSIndexPath的文档中,我能得到的最接近的是:

– indexPathByRemovingLastIndex
– indexPathByAddingIndex:
Run Code Online (Sandbox Code Playgroud)

这看起来有点麻烦.有没有办法可以覆盖索引数组的最后一个成员?

aka*_*kyy 12

NSIndexPath不是数组.它是一个具有2个只读属性的对象:rowsection.您无法更改它们,但是,您可以基于旧的indexPath 创建新的 indexPath:

NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:oldIndexPath.row inSection:1];
oldIndexPath = newIndexPath;
Run Code Online (Sandbox Code Playgroud)