Table View cellForRowAtIndexPath warning

后端 未结 3 532
长发绾君心
长发绾君心 2021-01-11 11:44

I have updated my code to swift 3.0 and get a warning on the following line:

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexP         


        
相关标签:
3条回答
  • 2021-01-11 11:54

    I had a similar problem, and found that if you remove the space between the underscore before tableView, from this

    func tableView(_ tableView: ...
    

    to this

    func tableView(_tableView: ...
    

    strangely the warning goes away...

    0 讨论(0)
  • 2021-01-11 11:55

    Just add the declaration of implementing UITableViewDataSource protocol to the class definition like this:

    class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {}
    
    0 讨论(0)
  • 2021-01-11 11:57

    In swift 3.0 the signature for the datasource changed to:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    

    Notice the difference between cellForRowAtIndexPath indexPath: IndexPath and cellForRowAt indexPath: IndexPath

    I'm using the new method without any warnings, hope this will solve your problem.

    Cheers.

    0 讨论(0)
提交回复
热议问题