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

前端之家收集整理的这篇文章主要介绍了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相关文章