当我实现任何一个建议的修复时,应用程序在运行时崩溃。当我在没有推荐修复的情况下编译/运行应用时,应用会按预期运行。
原方法如下:
func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
//this let statement is my original line of code prior to swift 3 conversion and it worked fine
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier:"Cell")
//i've tried using the statement below instead but still getting same error
//let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = userSummaryArray[(indexPath as NSIndexPath).row] as String
cell.textLabel!.font = UIFont(name:"Helvetica Neue", size:17)
cell.accessoryType = .disclosureIndicator
userSummaryTable.rowHeight = 25
return cell
}
在 Xcode8 中转换为 swift 3 后,我现在收到有关此方法的警告:
Instance method 'tableView(_:cellForIndexPath:)' nearly matches optional requirement 'tableView(_:heightForRowAt:)' of protocol 'UITableViewDelegate'
建议使用两个选项来“修复”警告:
Make 'tableView(_:cellForIndexPath:)' private to silence this warning
或
Add '@nonobjc' to silence this warning
这两个“修复”都会导致应用程序崩溃。原始代码在新的 swift 中运行良好,在旧版本的 swift 中运行良好。这些建议是什么?
非常感谢任何帮助。
最佳答案
做那个
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
代替
func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
Xcode 正试图帮助您,但没有意识到这一点
关于ios - 新的 Swift 3 警告崩溃应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39820437/