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所述.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...