问题描述
有谁知道NSIndexpath.row
和NSIndexpath.item
之间的区别?
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;
推荐答案
好吧,这里没有人给出好的答案.
Okay, nobody has given a good answer here.
在 NSIndexPath 中,索引存储在一个名为_indexes"的简单 c 数组中,定义为 NSUInteger*,数组的长度存储在定义为 NSUInteger 的_length"中.访问器section"是_indexes[0]"的别名,item"和row"都是_indexes[1]"的别名.因此两者在功能上是相同的.
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.
就编程风格而言——也许还有定义链——你最好在表的上下文中使用row",在集合的上下文中使用item".
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.
这篇关于NSIndexpath.item 与 NSIndexpath.row的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!