Reputation: 641
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?
Upvotes: 1
Views: 167
Reputation: 35372
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 { .. }
Upvotes: 1
Reputation: 2698
Try to cross check the following because you have added the xib explicitly in your bundle as your class name and xib name differs
Cross check 1
You have mentioned you custom class MenuTableViewCell
in Identity Inspector
window
Cross check 2
You have mention the cell identifier in the Attributes Inspector
window as
Upvotes: 0