我今天从 2.3 迁移到 Swift 3.0,并修复了所有编译器错误消息,但我在使用一个 TableView
时遇到问题。在我调用 reloadData()
并进入 numberOfSections
但在离开 numberOfRowsInSection
后,我在所有数据源方法之后放置了一个断点。 cellForRowAt
永远不会被击中。它在 AppDelegate
中崩溃,所以我不确定这是怎么回事。
我以前在运行 Swift 2.3 时没有遇到过这个问题,除非自动转换到 3.0 对这个特定的 TableView
做了一些事情。我的其他 TableView
运行良好。
最佳答案
使用下面的代码
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/