带有 Tableview 的自定义 Xib 单元格不起作用
Custom Xib Cell with Tableview isn't working
我正在使用以下教程使用 xib 文件创建滑出式菜单:
https://www.raywenderlich.com/78568/create-slide-out-navigation-panel-swift
现在我要使用自定义 tableview 单元格制作 xib tableview 视图。看了几个关于Whosebug的问题,我得到了下面的代码
override func viewDidLoad() {
super.viewDidLoad()
var nib = UINib(nibName: "MenuCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "menucell")
tableView.reloadData()
print("count: \(animals.count)")
}
和实际的单元格
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
}
但是表格视图没有显示带有标题的自定义表格视图单元格。谁能帮我解决这个问题?
可能是你忘记设置这个参数了:
tableView.delegate = self
tableView.datasource = self
如评论中所述:
更正您的 class 声明,例如:
class myClass: SidePanelViewController , UITableViewDataSource, UITableViewDelegate { .. }
尝试交叉检查以下内容,因为您已经在包中明确添加了 xib,因为您的 class 名称和 xib 名称不同
交叉检查 1
您在 Identity Inspector
window
中提到您自定义 class MenuTableViewCell
交叉检查 2
您在 Attributes Inspector
window 中提到了小区标识符作为
我正在使用以下教程使用 xib 文件创建滑出式菜单: https://www.raywenderlich.com/78568/create-slide-out-navigation-panel-swift
现在我要使用自定义 tableview 单元格制作 xib tableview 视图。看了几个关于Whosebug的问题,我得到了下面的代码
override func viewDidLoad() {
super.viewDidLoad()
var nib = UINib(nibName: "MenuCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "menucell")
tableView.reloadData()
print("count: \(animals.count)")
}
和实际的单元格
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
}
但是表格视图没有显示带有标题的自定义表格视图单元格。谁能帮我解决这个问题?
可能是你忘记设置这个参数了:
tableView.delegate = self
tableView.datasource = self
如评论中所述:
更正您的 class 声明,例如:
class myClass: SidePanelViewController , UITableViewDataSource, UITableViewDelegate { .. }
尝试交叉检查以下内容,因为您已经在包中明确添加了 xib,因为您的 class 名称和 xib 名称不同
交叉检查 1
您在 Identity Inspector
window
MenuTableViewCell
交叉检查 2
您在 Attributes Inspector
window 中提到了小区标识符作为