问题: NSIndexpath属性item和row的根本区别

来源:互联网 发布:xquartz for mac 编辑:程序博客网 时间:2024/06/05 10:10

问题

NSIndexpath属性item和row的根本区别是什么?

分析

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.

翻译过来就是, 在NSIndexPath中,其实例中存储在一个名为_indexes的简单的c数组中,定义为NSUInteger *,数组的长度存储在定义为NSUInteger_length中。 属性section_indexes[0]的别名,属性itemrow都是_indexes[1]的别名。 因此两者在功能上是相同的。

总结

虽然itemrow在功能上是一致的, 但是从编码风格上来说, 并且结合上下文环境来说, tableview中一般使用row会更好些, collectionview中一般使用item会更好些。

想了解更多, 看这里,参考资料:
NSIndexpath.item vs NSIndexpath.row

原创粉丝点击