Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSIndexpath.item vs NSIndexpath.row

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; 
like image 976
Cyberpass Avatar asked Feb 08 '13 04:02

Cyberpass


People also ask

What is IndexPath item?

IndexPath represents the path to a specific node in a tree of nested array collections. Each index in an index path represents the index into an array of children from one node in the tree to another, deeper, node.

What is IndexPath row?

Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section. For example, the first row in a table would have section 0, row 0, whereas the eighth row in the fourth section would have section 3, row 7.

What is NSIndexPath?

An object containing a list of indexes that bridges to IndexPath ; use NSIndexPath when you need reference semantics or other Foundation-specific behavior. iOS 2.0+ iPadOS 2.0+ macOS 10.4+ Mac Catalyst 13.0+ tvOS 9.0+ watchOS 2.0+


1 Answers

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.

like image 55
Owen Godfrey Avatar answered Oct 14 '22 11:10

Owen Godfrey