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

Car*_*son 13 nsindexpath ios uicollectionview uicollectionviewcell

当iOS 7.1发送我的viewController时:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
    cellForItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

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

调试器显示:

**indexPath NSIndexPath *   0xc000000000000016

 NSObject       
_indexes    NSUInteger *    NULL    
  *_indexes     
_length     
_reserved   void *  NULL
Run Code Online (Sandbox Code Playgroud)

日志报告:

(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****
Run Code Online (Sandbox Code Playgroud)

任何想法为什么会发生这种情况以及如何处理它?

Swi*_*ect 30

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

  1. po (int)[index row]
  2. po (int)[index section]

请注意,(int)必须将行/节打印为整数而不是十六进制.其他此类有用的LLDB格式参数可在此处找到.

编辑

Swift覆盖到Foundation框架提供了IndexPath结构,该结构桥接到NSIndexPath类.IndexPath值类型提供与NSIndexPath引用类型相同的功能,并且这两者可以在与Objective-C API交互的Swift代码中互换使用.此行为类似于Swift如何将标准字符串,数字和集合类型桥接到其对应的Foundation类.

  1. po index.row
  2. po index.section

按预期工作.关于pvs. 的评论po仍然有效.

值得注意的是,您可以IndexPathSwift中使用而不是NSIndexPath,如Apple文档中所述.


小智 11

你可以尝试这个,它对我来说很完美:

po (int)[indexPath row]
Run Code Online (Sandbox Code Playgroud)