ios - Swift 3 - 在 TableView 中的 numberOfRowsInSection 后崩溃

标签 ios swift swift3 tableview

我今天从 2.3 迁移到 Swift 3.0,并修复了所有编译器错误消息,但我在使用一个 TableView 时遇到问题。在我调用 reloadData() 并进入 numberOfSections 但在离开 numberOfRowsInSection 后,我在所有数据源方法之后放置了一个断点。 cellForRowAt 永远不会被击中。它在 AppDelegate 中崩溃,所以我不确定这是怎么回事。

我以前在运行 Swift 2.3 时没有遇到过这个问题,除非自动转换到 3.0 对这个特定的 TableView 做了一些事情。我的其他 TableView 运行良好。

Code

Crash

最佳答案

使用下面的代码

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        //if self.podcasts.count is nil then 0 will be returned. 
       if let count = self.podcasts.count{ 
             return count
       }
    return 0
}

如果您将某些内容异步加载到播客中并同时重新加载 TableView ,则播客可能为零,这会导致崩溃。

关于ios - Swift 3 - 在 TableView 中的 numberOfRowsInSection 后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41157969/

相关文章:

ios - Swift - 从一年中的某一天获取日期

ios - 在 IOS 上更改虚线粗细

callback - 不可能对回调函数进行 self 引用

ios - UIControl 类似于 iPhone 和 iPod Touch 上的 UIPopoverController

c++ - 如何在 iOS Objective-C 中捕获 C++ 异常代码?

swift - swift 中的核心数据简单获取请求模板

swift3 - 迅速3中的模数算子(%)是多少?

ios - 表格单元格约束无法正确加载

ios - 我想得到没有时间的今天日期

ios - Xcode Swift 秒表应用程序