Search code examples
objective-cioscocoa-touchnsindexpath

Shift NSIndexPath entities


I read NSIndexPaths all the time for uitableviews etc. But I'm having difficultly manipulating an existing indexpath.

I want to take an existing indexpath increment/shift each section while preserving the rows. So that indexPath.section 0 becomes indexPath.section 1 etc. moving the associated row count non-desctructively.

I know NSIndexPath is immutable but are their any categories or nice patterns that support this?


Solution

  • Well, you could always just create a new slightly changed instance from the old one.

    NSIndexPath *newPath = [NSIndexPath indexPathForRow:oldPath.row 
                                              inSection:oldPath.section+1];