Gloria Globo Cvl
Gloria Globo Cvl

Reputation: 1

type viewcontroller does not conform to protocol uitableviewdatasource

I already done the same tableview in another view but in this one could not work. I'm also looking for an solution but i don't know what doesn't work

class HistoryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var tableview: UITableView!

var date = ["ciao", "muori"]
var place = ["aaaa"]



override func viewDidLoad() {
    super.viewDidLoad()

    tableview.dataSource = self
    tableview.delegate = self

    // Do any additional setup after loading the view.
}


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

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

func tableview(tableView: UITableView, cellForRowIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = self.tableview.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! HistoryCell
    cell.placeLabel.text = place[indexPath.row]
    cell.dateLabel.text = date[indexPath.row]
    return cell

}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{

}

someone could help me?

Upvotes: 0

Views: 1561

Answers (3)

vadian
vadian

Reputation: 285079

  • Goto Issue Navigator (⌘4).
  • Open the disclosure triangle next to the error message.
  • Implement the missing required methods which are displayed beneath the error message.

And use code completion to avoid those typos.

Upvotes: 3

Julien Quere
Julien Quere

Reputation: 2459

You've made a mistake in the method name: you have to implement tableView:cellForRowAtIndexPath: not tableview:cellForRowIndexPath:. Here is a correct implementation :

class HistoryViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tableview: UITableView!

    var date = ["ciao", "muori"]
    var place = ["aaaa"]

    override func viewDidLoad() {
        super.viewDidLoad()

        tableview.dataSource = self
        tableview.delegate = self

        // Do any additional setup after loading the view.
    }

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

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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableview.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! HistoryCell
        cell.placeLabel.text = place[indexPath.row]
        cell.dateLabel.text = date[indexPath.row]
        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
    {
    }
}

Upvotes: 1

Budyn
Budyn

Reputation: 134

Please check if

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

and

func tableView(tableView:UITableView, numberOfRowsInSection section:Int)

are inserted inside class {} brackets.

Upvotes: 0

Related Questions