Swift 表 : indexPath. 行返回 -1

标签 swift

有时,当我滑动一行并使用 iOS 模拟器输入 editActionsForRowAtIndexPath 时,indexPath.row 等于 -1。这是一种非常罕见的情况,因此很难调试,除了等待代码中的 println(indexPath.row) 之外,这就是我知道它返回 -1 的方式。有没有其他人有这方面的经验?

最佳答案

NSIndexPath 行的整数是一个带符号的 NSInteger,而不是 NSUInteger。这样做的原因可能是因为无符号类型很容易下溢。这意味着 -1 的索引路径行将返回大约 4294967294 的行值。

answer声称 UITableView 的早期版本使用 NSInteger 作为监督,Apple 将所有内容(部分、行数等)更改为 NSUInteger 使有符号和无符号类型和谐地工作将是一项艰巨的任务。

如果您在代码中遇到从 indexPath.row 中减去 1 的情况,当索引为 0 时,将发生此行为。

关于Swift 表 : indexPath. 行返回 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32170686/

相关文章:

ios - swift 3 : Error in TableView when deleting cells holding UserDefault values

ios - 在 Swift 中将 NSLog 重定向到文件不起作用

ios - 如何使用 Swift 的 prepareForSegue 函数指定要准备的 View Controller ?

ios - 用户界面 TextView /NSAttribute : Detect if word starts with a particular symbol

ios - 动态选择 UIPicker 行

swift - MIDIThruConnectionCreate 总是通过连接创建持久的 MIDI?

ios - Swift Range 的 NSRange?

objective-c - SwiftSupport 文件夹丢失。使用当前公共(public) (GM) 版本的 Xcode 重建您的应用程序并重新提交

swift - 为什么代码会产生错误 Type '(int, int)' does not conform to protocol 'IntegerLiteralConvertible'

swift - 如何在 Xcode/Swift com.apple.developer.healthkit.background-delivery 中添加此权利?