NSIndexpath.item vs NSIndexpath.row

Cyberpass picture Cyberpass · Feb 8, 2013 · Viewed 28.6k times · Source

Does anyone know the difference between NSIndexpath.row and NSIndexpath.item?

Specifically, which one do I use in:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

Answer

Owen Godfrey picture Owen Godfrey · Jun 19, 2013

Okay, nobody has given a good answer here.

Inside NSIndexPath, the indexes are stored in a simple c array called "_indexes" defined as NSUInteger* and the length of the array is stored in "_length" defined as NSUInteger. The accessor "section" is an alias to "_indexes[0]" and both "item" and "row" are aliases to "_indexes[1]". Thus the two are functionally identical.

In terms of programming style – and perhaps the definition chain – you would be better using "row" in the context of tables, and "item" in the context of collections.