NSIndexpath.item vs NSIndexpath.row
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.
indexPath.row is best in your case
First info about NSIndexPath
The NSIndexPath
class represents the path to a specific node in a tree of nested array collections. This path is known as an index path.
Each index in an indexPath represents the index into an array of children from one node in the tree to another, deeper node.
For example, the indexPath 1.4.3.2 specifies the path shown in Figure
Here in your case indexPath.row
returns the index of the row at the specific indexPath
.
Differences between indexPath.row and indexPath.item
Generally indexPath
has two properties
1 - row
2 - item
row - property use with UITableView
for get specific row base on indexPath. it is also read only property
Available in iOS 2.0 and later.
item - properly use with UICollectionView
for get item in section. It is a read-only property. To use this property you need to declare it in
UICollectionView.h
> Available in iOS 6.0 and later.
You need to use indexPath.row
Difference is that:
indexPath.row is for tableView and indexPath.item is for collectionView.
item
An index number identifying an item in a section of a collection view. (read-only)
@property (nonatomic, readonly) NSInteger item;
Discussion
The section the item is in is identified by the value of section. Availability
Available in iOS 6.0 and later.
Declared In UICollectionView.h
row
An index number identifying a row in a section of a table view. (read-only)
@property(nonatomic, readonly) NSInteger row;
Discussion
The section the row is in is identified by the value of section. Availability
Available in iOS 2.0 and later.
Please check the NSIndexPath Additions for details