KNV KNV - 5 months ago 21
Swift Question

Custom Xib Cell with Tableview isn't working

I'm creating a slide out menu with xib files using the following tutorial:
https://www.raywenderlich.com/78568/create-slide-out-navigation-panel-swift

Now I'm at the point to make the xib tableview view with the custom tableview cell. Reading several questions on stackoverflow I came to the following code

override func viewDidLoad() {
super.viewDidLoad()

var nib = UINib(nibName: "MenuCell", bundle: nil)

tableView.registerNib(nib, forCellReuseIdentifier: "menucell")
tableView.reloadData()

print("count: \(animals.count)")
}


and the actual cell

extension SidePanelViewController: UITableViewDataSource {

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

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

return animals.count
}

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

var cell:MenuTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("menucell", forIndexPath: indexPath) as! MenuTableViewCell

cell.configureCell(animals[indexPath.row])
return cell
}


But the tableview is not showing the custom tableview cells with the title. Can anyone help me with this problem?

Answer

Probably you have forgot to set this parameters:

tableView.delegate = self
tableView.datasource = self

As explained in comments:

Correct your class declaration like this for example:

class myClass: SidePanelViewController , UITableViewDataSource, UITableViewDelegate { .. }