#import <Foundation/NSObject.h>
@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;
// comparison support
- (NSComparisonResult)compare:(NSIndexPath *)otherObject; // sorting an array of indexPaths using this comparison results in an array representing nodes in depth-first traversal order
@end
查看NSIndexPath头文件发现并没有这两个属性,于是我去查看官方文档发现这个
The NSIndexPath
class represents the path to a specific node in a tree of nested array collections. This path is known as an index path.
Each index in an index path represents the index into an array of children from one node in the tree to another, deeper, node. For example, the index path 1.4.3.2
specifies the path shown in Figure 1.
NOTE
iOS adds programming interfaces to the NSIndexPath
class of the Foundation framework to facilitate the identification of rows and sections in UITableView
objects. The API consists of a class method and two properties. The indexPathForRow:inSection:
method creates an NSIndexPath
object from row
and section
index numbers. The properties return the row
index number and the section
index number from such objects. See NSIndexPath UIKit Additions for details.
// This category provides convenience methods to make it easier to use an NSIndexPath to represent a section and row
@interface NSIndexPath (UITableView)
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
@property(nonatomic,readonly) NSInteger section;
@property(nonatomic,readonly) NSInteger row;
@end
可以看出, 通过分类实现这一功能的, 但是分类不是只能添加方法不能添加属性吗?
这里用到运行时关联引用
http://www.jianshu.com/p/3cbab68fb856