在UITableView中,我可以在.h文件中看到这些:
@interface NSIndexPath (UITableView)
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
@property(nonatomic,readonly) NSInteger section;
@property(nonatomic,readonly) NSInteger row;
@end
在UICollectionView中,我可以找到这个类别:
@interface NSIndexPath (UICollectionViewAdditions)
+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
@property (nonatomic, readonly) NSInteger item NS_AVAILABLE_IOS(6_0);
@end
但是,如果在collectionView的委托类中,我引用" section"在CollectionView的indexPath中的属性,Xcode没有警告,为什么?
-(NSInteger)collectionView:(UICollectionView*)cv numberOfItemsInSection:(NSInteger)section {
if (cv == self.collectionView) {
if (cv.collectionViewLayout == self.layout2) {
return [self.searches count];
} else {
NSString *searchTerm = self.searches[section];
return [self.searchResults[searchTerm] count];
}
} else if (cv == self.currentPinchCollectionView) {
//commend for below == @property (nonatomic, strong) NSIndexPath *currentPinchedItem;
NSString *searchTerm = self.searches[self.currentPinchedItem.section];// this "section" is NOT for tableView, why NO warning/error from Xcode?
return [self.searchResults[searchTerm] count];
}
return 0;
}
答案 0 :(得分:1)
我的猜测是在UITableView.h中创建了IndexPath对象。然后将item属性添加到UICollectionView.h中的IndexPath类别,因为行属性在集合视图中没有任何意义。但是,section仍然是框架中随处可用的属性,因为它是索引路径的重点。