Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type "First View Controller" does not conform to protocol "UITableViewDataSource"

So I can't seem to get this error away..

My code is:

class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    @IBOutlet var tblTasks: UITableView!

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

    //UITableViewDataSource
    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
    }
}

I used both of the required functions for UITableViewDataSource so I'm not sure why I keep getting this error.

like image 520
James Avatar asked Dec 03 '25 14:12

James


2 Answers

Try changing the method signatures as mentioned below. Notice ! is removed in the input params.

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

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->  UITableViewCell {
}
like image 200
Nitin Arora Avatar answered Dec 06 '25 05:12

Nitin Arora


Neither of each method's respective tableView parameters should be optionals

like image 22
Wayne Avatar answered Dec 06 '25 06:12

Wayne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!