NSIndexPath indexPathByRemovingLastIndex
- (NSIndexPath *)indexPathByRemovingLastIndex
Return Value
New index path with the receiving index path’s indexes, excluding the last one.
Discussion of [NSIndexPath indexPathByRemovingLastIndex]
Returns an empty NSIndexPath instance if the receiving index path’s length is 1 or less.
Special Considerations
On OS X v10.4 this method returns nil when the length of the receiving index path is 1 or less. On iOS and OS X v10.5 and later this method will never return nil.
NSIndexPath indexPathByRemovingLastIndex example.
You can try this - perhaps equally clunky, but at least a bit shorter:
NSInteger newLast = [indexPath indexAtPosition:indexPath.length-1]+1;
indexPath = [[indexPath indexPathByRemovingLastIndex] indexPathByAddingIndex:newLast];
NSInteger newLast = [indexPath indexAtPosition:indexPath.length-1]+1;
indexPath = [[indexPath indexPathByRemovingLastIndex] indexPathByAddingIndex:newLast];