【Foundation-36-1】#import <Foundation/NSIndexPath.h>树结构



NSIndexPath 让你精确指定一个树结构 data structure 里面的某个节点的数据
比如你有一个 NSArray, 里面很多节点,每个节点又是一个 NSArray,每个节点的这个里面又是一个NSArray,然后下面又是一个  NSArray
这样简单说起来,你有一个四层的 NSarray ,每层下面都有好多个 NSArray。
然后你造一个  NSIndexPath 1.3.4.2
你就可以拿它访问      第一层第三个节点之下第四个节点第二个节点的数据


常见的就是 UITableView 的 section  和 row


@interface NSIndexPath : NSObject <NSCopying, NSSecureCoding> {

@private

__strong NSUInteger *_indexes;

#if !__OBJC2__

NSUInteger _hash;

#endif

NSUInteger _length;

        void *_reserved;

}


+ (instancetype)indexPathWithIndex:(NSUInteger)index;

+ (instancetype)indexPathWithIndexes:(const NSUInteger [])indexes length:(NSUInteger)length;


- (instancetype)initWithIndexes:(const NSUInteger [])indexes length:(NSUInteger)length NS_DESIGNATED_INITIALIZER;


- (instancetype)initWithIndex:(NSUInteger)index;



- (NSIndexPath *)indexPathByAddingIndex:(NSUInteger)index;

- (NSIndexPath *)indexPathByRemovingLastIndex;


- (NSUInteger)indexAtPosition:(NSUInteger)position;

@property (readonly) NSUInteger length;


- (void)getIndexes:(NSUInteger *)indexes;


- (NSComparisonResult)compare:(NSIndexPath *)otherObject; // 


@end




// 这个是在 UITableView 里的拓展

@interface NSIndexPath (UITableView)


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

    NSIndexPath *path = [NSIndexPath indexPathForRow:5 inSection:2];


@property(nonatomic,readonly) NSInteger section;

@property(nonatomic,readonly) NSInteger row;


@end




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值