gpt4 book ai didi

ios - NSIndexPath 无法将项目、部分或行识别为属性

转载 作者:技术小花猫 更新时间:2023-10-29 10:18:59 25 4
gpt4 key购买 nike

当 iOS 7.1 发送我的 viewController 时:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
cellForItemAtIndexPath:(NSIndexPath *)indexPath

indexPath 对象无法识别以下属性:项目、部分或行。预期值为 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 点语法,使用括号:

  1. po (int)[索引行]
  2. po (int)[索引部分]

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

编辑

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.

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

按预期工作。关于 ppo 的评论仍然有效。

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

关于ios - NSIndexPath 无法将项目、部分或行识别为属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24622563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com