How to create an NSIndexPath and specify its components

On occasion we need to create an NSIndexPath manually, with components we specify (such as a row or a section). There’s a method for that: indexPath:forItem:inSection.

Here’s how you create an indexPath for row 0, section 0:

The method takes two integers. You can even take an existing indexPath, then add or subtract values to the new indexPath, like so:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.