2016-10-02 32 views
1

當我實現任一提議修復應用程序崩潰時運行。當我編譯/運行應用程序沒有建議的修復應用程序按預期運行。新的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中正常工作。這些建議是什麼?

任何幫助,非常感謝。

回答

5

作出這樣的

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

你只需要遵循自動完成,它會工作,乾淨的項目,並請顯示你的方法添加自動完成和什麼崩潰錯誤說,當出現崩潰必須有一些消息 –

1

我有同樣的問題。與Lu_s答案一起,確保將UITableViewDataSource添加到類中。

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { }