ios - 新的 Swift 3 警告崩溃应用程序

标签 ios swift swift3

当我实现任何一个建议的修复时,应用程序在运行时崩溃。当我在没有推荐修复的情况下编译/运行应用时,应用会按预期运行。

screen shot of error is at this link

原方法如下:

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/

相关文章:

来自 URLComponents 的 Swift3 URL,如何添加或查询项目

ios - 将 Paytm 与 swift 3.0 集成

swift - Storyboard的 View Controller 之间共享变量?

ios - UISearchBar 访问 UIAccessibility 的明文按钮

ios - 如何在 iOS 应用程序中防止来电干扰

ios - 访问 MFMessageComposeViewController 的第一响应者

node.js - 使用 Node.js 通过自定义 API 向设备(ios 或 android)发送通知

ios - 在这种情况下如何传递segue数据?

ios - AWS AppSync 订阅 iOS 的特定设备/用户?

iphone - 倾斜 iPhone 以更改 UIImage(加速计)