UITableview:无法从其数据源获取单元格 [英] UITableview: failed to obtain a cell from its dataSource
问题描述
我收到此错误消息:无法从其数据源获取单元格
奇怪的是
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell {
甚至没有被调用,问题不在于返回的单元格为零.我设置了断点.cellForRowAt
没有被调用.
not even get called, problem is not that returned cell is nil. I put in breakpoints. cellForRowAt
not get called.
numberOfRowsInSection
返回值.
我不知道它是否相关,但现在我不使用UITableViewController
,我只有一个UIViewController
,它是datasource
和 delegate
用于 UITableView
.我希望它不会造成干扰.有什么想法吗?
I do not know it is relating or not, but now I do not use UITableViewController
, I just have a UIViewController
, and it is the datasource
and delegate
for the UITableView
. I hope it can not cause interfere. Any idea?
推荐答案
交叉检查以下检查清单:-
Cross check below check list:-
- 这是因为您无法使可重用单元出列.
- 问题在于您的 cellForRowAtIndexPath 函数嵌入在另一个函数中
- 当您忘记将 UITableViewDataSource 和 UITableViewDelegate 协议添加到
ViewController 声明
时.
类 DataViewController:UIViewController、UITableViewDataSource、UITableViewDelegate
class DataViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
这篇关于UITableview:无法从其数据源获取单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!