Search code examples
iosnsindexpath

How can I get the "row" from indexPathsForSelectedRows?


I am trying to get the "row" value from indexPathsForSelectedRows.

NSArray *selectedCells = [self.storeTableView indexPathsForSelectedRows];
NSLog(@"%@",[selectedCells objectAtIndex:0]);

This NSLog prints out

<NSIndexPath: 0xc000000000008016> {length = 2, path = 0 - 4}

How can I just get the number '4' as an integer in this example?

I've tried objectForKey@"path". but it did not work.


Solution

  • You can do

    NSArray *selectedCells = [self.storeTableView indexPathsForSelectedRows];
    NSIndexPath *firstIndexPath = [selectedCells objectAtIndex:0];
    NSUInteger row = firstIndexPath.row
    

    and row will be 4 in your case.