具有两个不同的tableview单元格的两个tableview

时间:2018-07-18 09:50:50

标签: ios swift xcode

我有两个带有两个不同的自定义表视图单元格的表视图。并且正在执行此操作:

$('#searchindexcheckinout').datepicker({
  language: 'fr',
  minDate: new Date(),
  firstDay: 0
});

当然我已经从情节提要中注册了它们。

enter image description here

enter image description here

enter image description here

enter image description here

但是我一直得到这个:

enter image description here

在此行:

  

让单元格= tableview.dequeueReusableCell(withIdentifier:“ filtercell”)为! FilterTableViewCell

试图像这样注册它们:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if tableView == self.tableview {
        let cell = tableview.dequeueReusableCell(withIdentifier: "matchescell") as! MatchesTableViewCell
        // ......
        return cell
    } else {
        let cell = tableview.dequeueReusableCell(withIdentifier: "filtercell") as! FilterTableViewCell
        // ......
        return cell
    }
}

但仍然出现相同的错误!

在做什么错了?!

7 个答案:

答案 0 :(得分:2)

问题是您在其他部分键入了“ tableview”而不是“ tableView”:

替换:

let cell = tableview.dequeueReusableCell(withIdentifier: "filtercell") as! FilterTableViewCell

与:

let cell = tableView.dequeueReusableCell(withIdentifier: "filtercell") as! FilterTableViewCell

它崩溃了,因为您的“表视图”没有注册此单元格。

答案 1 :(得分:0)

在情节提要或Xib自定义单元格(FilterTableViewCell)中添加“ filtercell”标识符。

答案 2 :(得分:0)

可能的原因:

  • 您尚未将单元格的类或单元格注册到正确的表视图
  • 您尚未在笔尖/故事板上的单元格视图中设置标识符
  • 您已经反转了表格视图及其单元格类型

答案 3 :(得分:0)

这是因为您没有注册单元格

String code = jsonObj.opt("code");
if(!arrayList.contains(code))
{
    arrayList.add(code);
    responseObj.put("id", jsonObj.opt("id")); 
    responseObj.put("code", jsonObj.opt("code")); 
    responseObj.put("long_description", long_description);
    responseObj.put("description", description);
}

//

tableView.register(CustomCellClass.self, forCellReuseIdentifier: "CellID")

或者您将表的出队行交换了

答案 4 :(得分:0)

在情节提要中查看Tableview控制器。您应该有一个不同于呼入的压头:

let cell = tableview.dequeueReusableCell(withIdentifier: "filtercell") as! FilterTableViewCell

答案 5 :(得分:0)

顺便说一句,您应该始终使用此较新的功能

dequeueReusableCell(withIdentifier:for:)

代替

dequeueReusableCell(withIdentifier:)

有关详细信息,请参见this post

答案 6 :(得分:-1)

您可以轻松地解决此问题,只需检查您当时使用的表视图即可。 您可以尝试使用此代码,

func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) {

如果(tableview ==(yourtableview 1))

{

let cell = yourtableview 1.dequeueReusableCell(withIdentifier:“ yourtableview Cell 1”)as? yourtableview单元格1 }

其他 {  让单元格= yourtableview 2.dequeueReusableCell(withIdentifier:“ yourtableview单元格2”)为吗? yourtableview单元格

}

返回单元格

}

相关问题