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

问题描述:

当我实现任一提议修复应用程序崩溃时运行。当我编译/运行应用程序没有建议的修复应用程序按预期运行。新的Swift 3警告崩溃应用程序

screen shot of error is at this link

原来的方法如下:

Instance method 'tableView(_:cellForIndexPath:)' nearly matches optional requirement 'tableView(_:heightForRowAt:)' of protocol 'UITableViewDelegate' 

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 

} 

转换为SWIFT 3 Xcode8现在我对这种方法读取得到警告后,有两个选项建议“修复”警告:

Make 'tableView(_:cellForIndexPath:)' private to silence this warning 

OR

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是想帮你,但不承认

+0

我改变了你的建议,但我的应用程序崩溃时运行,所以我已经恢复到了“FUNC的tableView(_的tableView:UITableView的,的cellForRowAtIndexPath indexPath:IndexPath) - > {UITableViewCell的”代码和应用程​​序成功运行;但我仍然没有解决我的原始问题....为什么我得到这种方法有关的两个警告? –

+0

你只需要遵循自动完成,它会工作,干净的项目,并请显示你的方法添加自动完成和什么崩溃错误说,当出现崩溃必须有一些消息 –

我有同样的问题。与Lu_s答案一起,确保将UITableViewDataSource添加到类中。

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { }