問題: NSIndexpath屬性item和row的根本區別

問題

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

發佈了209 篇原創文章 · 獲贊 128 · 訪問量 58萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章