ios – NSIndexPath不会将项目,部分或行识别为属性

当iOS 7.1发送我的viewController时:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
    cellForItemAtIndexPath:(NSIndexPath *)indexPath

indexPath对象无法识别属性:item,section或row.期望值为section = 0,item = 0

调试器显示

**indexPath NSIndexPath *   0xc000000000000016

 NSObject       
_indexes    NSUInteger *    NULL    
  *_indexes     
_length     
_reserved   void *  NULL

日志报告:

(lldb) po indexPath
<NSIndexPath: 0xc000000000000016> {length = 2,path = 0 - 0}
(lldb) po indexPath.item
error: property 'item' not found on object of type 'NSIndexPath *'
error: 1 errors parsing expression
(lldb) po indexPath.row
error: property 'row' not found on object of type 'NSIndexPath *'
error: 1 errors parsing expression
(lldb) po indexPath.section
error: property 'section' not found on object of type 'NSIndexPath *'
error: 1 errors parsing expression****

任何想法为什么会发生,该怎么做?

解决方法

不要使用getter / setter点语法,使用括号:

> po [index row]
> po [index section]

编辑

The Swift overlay to the Foundation framework provides the IndexPath structure,which bridges to the NSIndexPath class. The IndexPath value type offers the same functionality as the NSIndexPath reference type,and the two can be used interchangeably in Swift code that interacts with Objective-C APIs. This behavior is similar to how Swift bridges standard string,numeric,and collection types to their corresponding Foundation classes.

> po index.row
> po index.section

按预期工作.对p对po的评论仍然存在.

值得注意的是,您可以使用Swift中的IndexPath,而不是NSIndexPath,如Apple Documentation所述.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...