Ios 如何在UICollectionview中向UITableview添加单元格

Ios 如何在UICollectionview中向UITableview添加单元格,ios,swift,uitableview,Ios,Swift,Uitableview,我有一个收藏视图 class ChatLogController:UICollectionViewController 里面还有一个桌面视图 let colors: UITableView = { let div = UITableView(); div.backgroundColor = UIColor(white: 0.90, alpha: 1) return div; }() 现在我想将单元格添加到颜色表中,我应该将numberOfSectionsInTableV

我有一个收藏视图
class ChatLogController:UICollectionViewController

里面还有一个桌面视图

let colors: UITableView = {
    let div = UITableView();
    div.backgroundColor = UIColor(white: 0.90, alpha: 1)
    return div;
}()

现在我想将单元格添加到颜色表中,我应该将
numberOfSectionsInTableView
函数放在哪里?

您应该将
datasource
delegate
添加到
UITableView
中。给你和我的一些阅读资料

应该如此

div.datasource = self
div.delegate = self
对于
UITableView
datasource
delegate
类,添加用于呈现和填充单元格数据的方法

编辑代码示例

class ViewController: UIViewController {

    let colors: UITableView = {
        let div = UITableView();
        div.backgroundColor = UIColor(white: 0.90, alpha: 1)
        return div;
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        colors.dataSource = self
    }
}

extension ViewController: UITableViewDataSource {

    func numberOfSections(in tableView: UITableView) -> Int {
        return 5
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
        let label = UILabel()
        label.text="saksaokoask"
        cell.addSubview(label)
        return cell
    }
}

'NSInternalInconsistencyException',原因:“无法将标识符为reuseIdentifier的单元格出列-必须为标识符注册nib或类,或在情节提要中连接原型单元格”
是您应该为自定义表视图注册自己的单元格。请阅读有关如何使用表格视图的内容。@BrunoSnickers