does not confirm to protocol UITableViewDataSource

2020-05-08 08:20发布

Here is my Code , Compiler is still showing error although I wrote implementation of both methods

Please tell why

import UIKit

class FirstViewController: UIViewController , UITableViewDelegate, UITableViewDataSource     {

        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }

        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }

        func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
            return taskMgr.tasks.count
        }


        func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

            let cell : UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "test")
            cell.textLabel?.text = taskMgr.tasks[indexPath.row].name
            cell.detailTextLabel?.text = taskMgr.tasks[indexPath.row].desc

            return cell
        }

    }

Here is screenshot of Xcode enter image description here

1条回答
forever°为你锁心
2楼-- · 2020-05-08 08:51

You have probably written this code in a previous version of Xcode. The correct signature for the 2 methods has changed, and it's now:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

The tableView parameter is no longer an optional.

查看更多
登录 后发表回答