Search code examples
objective-cnsindexpath

difference between indexPath and indexPath.row (iphone)


i am confused about indexPath and indexPath.row, does each cell of a tableView correspond to an indexPath? so why do we look for the "row" of this indexPath? i checked the doc but i think it confuses me.

i found this code :

// this method is used in case the user scrolled into a set of cells that don't have their app icons yet
- (void)loadImagesForOnscreenRows
{
    if ([self.entries count] > 0)
    {
        NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];
        for (NSIndexPath *indexPath in visiblePaths)
        {
            AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];

            if (!appRecord.appIcon) // avoid the app icon download if the app already has an icon
            {
                [self startIconDownload:appRecord forIndexPath:indexPath];
            }
        }
    }
}

Can you explain me the difference between the two?

Thanks a lot

Paul


Solution

  • Each instances of NSIndexPath class has two properties: row and section (Documentation)
    Each cell of tableView corresponds to unique indexPath (N-th row in M-th section). Often there is only one section and people use only row to reference to the data.