iOS陸哥開發筆記(二十六) (NSIndexPath)

Foundation框架中的一個普通的類,它提供了到嵌套數列的樹中特定節點的路徑,事實上,它是一個整數陣列,表格視圖使用這個去表現在特定章節中的特定行,UITableView用的所有索引路徑正好有兩個元素,第一個是章節,第二個是行。
圖片

NSIndexPathTableViews

@interfaceNSIndexPath (UITableView) {

}

+(NSIndexPath*)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section;

@property(nonatomic,readonly)NSUIntegerrow;

@property(nonatomic,readonly)NSUIntegersection;

@end



NSIndexPath是一種特別的資料類別,這是用來表示一個路徑,這個路徑是指到一個從0開始的巢狀集合陣列樹狀結構的某個節點。iPhone OS為UITableView擴充了這個類別(見NSIndexPath UIKit Additions這是用分類擴充),加入了一個用來建立新的NSIndexPath實體的「(NSIndexPath *)indexPathForRow:(NSUInteger)row inSection:(NSUInteger)section」方法和row和section兩個屬性。


nsindexpath的compare方法:
compare:

Indicates the depth-first traversal order of the receiving index path and another index path.

- (NSComparisonResult)compare:(NSIndexPath *)indexPath
Parameters
indexPath

Index path to compare.

This value must not be nil. If the value is nil, the behavior is undefined.

Return Value

The depth-first traversal ordering of the receiving index path and indexPath.

Availability
  • Available in Mac OS X v10.4 and later.
Declared In
NSIndexPath.h
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章