KNV KNV - 1 year ago 58
Swift Question

Custom Xib Cell with Tableview isn't working

I'm creating a slide out menu with xib files using the following tutorial:

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() {

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

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

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

return cell

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

Answer Source

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 { .. }