Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift tableView delegate method is not getting called

I have created a tableview controller but its delegate methods are not getting called. I referred a few web sites and didn't came across any mistake in my code. Please help me.

class FriutsTableViewController: UITableViewController {
var fruitsList : [AnyObject] = ["We", "love", "swift"];

override func viewDidLoad() {
    super.viewDidLoad()

    let myCatalog = Catalog()
    fruitsList = myCatalog.fruits;
    //let view = ViewController()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
    return 0
}

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

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    var cell  = tableView.dequeueReusableCellWithIdentifier("fruitIdentifier") as? UITableViewCell

    if !cell {
        cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "fruitIdentifier")
    }

    cell!.textLabel.text = fruitsList[indexPath.row] as AnyObject! as String!
    return cell
}

@objc func fetchFruits() {

}

Thanks in advance.

like image 962
selva Avatar asked Dec 26 '22 03:12

selva


1 Answers

Try to

return 1 

in

numberOfSectionsInTableView.
like image 170
derdida Avatar answered Jan 16 '23 19:01

derdida