Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 带有Tableview的自定义Xib单元格不';行不通_Swift_Uitableview_Tableviewcell - Fatal编程技术网

Swift 带有Tableview的自定义Xib单元格不';行不通

Swift 带有Tableview的自定义Xib单元格不';行不通,swift,uitableview,tableviewcell,Swift,Uitableview,Tableviewcell,我正在使用以下教程创建包含xib文件的滑出菜单: 现在我要用自定义tableview单元格创建xib tableview视图。在阅读有关stackoverflow的几个问题后,我得到了以下代码 override func viewDidLoad() { super.viewDidLoad() var nib = UINib(nibName: "MenuCell", bundle: nil) tableView.registerNib(nib, forCell

我正在使用以下教程创建包含xib文件的滑出菜单:

现在我要用自定义tableview单元格创建xib tableview视图。在阅读有关stackoverflow的几个问题后,我得到了以下代码

    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没有显示带有标题的自定义tableview单元格。有人能帮我解决这个问题吗

您可能忘记设置此参数:

tableView.delegate = self
tableView.datasource = self

如评论中所述:


更正您的类声明,例如:

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

请尝试交叉检查以下内容,因为您已在包中显式添加了xib,因为您的类名和xib名称不同

交叉核对1

您已经在
标识检查器
窗口中提到了您的自定义类
菜单视图单元格

交叉核对2

您在
属性检查器
窗口中提到了单元格标识符

您包中的xib名称是什么?它是“MenuCell”吗?您在属性检查器窗口中提到“MenuCell”作为标识符了吗?我必须在哪里添加它?您可以将它添加到ViewDidLoad中更正您的类声明,例如:类myClass:SidePanelViewController、UITableViewDataSource、UITableViewDelegate{..}问题是什么?如果这有帮助,请接受作为答案,以便其他所有人都能立即知道并获得帮助请参见Alessandro,按如下方式更正您的类声明,例如:类myClass:SidePanelViewController、UITableViewDataSource、UITableViewDelegate{..}