iOS – Get the NSIndexPath for a UITableViewCell by Row and Section

Here’s a newby tip for iPhone and iPad developers…I am noob too 😉

I was trying to build an indexPath based on a row # and section, but none of the constructors I tried seemed to work…stuff like indexPathWithIndex: or indexPathWithIndexes:length. Back to the class reference for more reading. I found the answer in the NSIndexPath UIKit Additions section.

NSIndexPath Class Method – indexPathForRow:inSection:

Here’s an example:

NSIndexPath *myIndexPath = [NSIndexPath indexPathForRow: 0 inSection:1];

Nice and simple, not sure why I didn’t see it the first 3 times I looked!



Comments are closed.

Powered by WordPress. Designed by Woo Themes