在willDisplay中配置自定义单元格

时间:2017-08-28 09:08:37

标签: swift uitableview swift3

UITableViewDataSrouce看起来像:

我将cellForRowAt内的单元格取消:

...

case is ComponentType:
            return tableView.dequeueReusableCell(withIdentifier: "checkboxCell") as! ComponentTypeCell

...

willDisplay内配置数据单元格:

...

case is ComponentType:
            guard let cell = cell as? ComponentTypeCell else { return }
            cell.configure(with: model, at: indexPath)

...

问题出在哪里?我的UITableView具有自行调整大小的单元格,cellForRowAtwillDisplay之间的区别在于:如果在我的configure(...)方法中,我有:

titleLabel.text = "Something"

并且调用将在willDisplay内部,如上所述,它不会显示任何文本,并且单元格将具有默认大小。当我将呼叫交换到cellForRowAt时,它将起作用。任何想法为什么会发生这种情况?这有点威胁。

提前致谢!

1 个答案:

答案 0 :(得分:0)

目前还不是很清楚这似乎是什么问题,但试试看, 首先用安全的方法替换这个方法:

case is ComponentType:
            return tableView.dequeueReusableCell(withIdentifier: "checkboxCell") as! ComponentTypeCell

tableView.dequeueReusableCell(type: "checkboxCell", forIndexPath: indexPath)

如果你还没有,还包括这个:

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44
相关问题