更改NSIndexPath对象的值

时间:2012-02-04 09:04:48

标签: iphone cocoa

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

unsigned i_array[] = { 0, 0};
i_array[1] = 1;

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

– indexPathByRemovingLastIndex
– indexPathByAddingIndex:

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

2 个答案:

答案 0 :(得分:10)

NSIndexPath不是数组。它是一个具有2个只读属性的对象:rowsection。您无法更改它们,但是,您可以根据旧的索引路径创建索引路径:

NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:oldIndexPath.row inSection:1];
oldIndexPath = newIndexPath;

答案 1 :(得分:0)

indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
相关问题