Ios 在tableViewCell中添加tableView

Ios 在tableViewCell中添加tableView,ios,swift,uitableview,Ios,Swift,Uitableview,我试图在表视图单元格中使用表视图。这是我的密码 class TableViewInsideCell: UITableViewCell, UITableViewDelegate, UITableViewDataSource{ @IBOutlet weak var tableView: UITableView! override func awakeFromNib() { super.awakeFromNib() // Initializatio

我试图在表视图单元格中使用表视图。这是我的密码

class TableViewInsideCell: UITableViewCell, UITableViewDelegate, UITableViewDataSource{

    @IBOutlet weak var tableView: UITableView!


    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code

        tableView.delegate = self
        tableView.dataSource = (self as! UITableViewDataSource)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
          return 5
      }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }

     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell( withIdentifier: "identifier",for: indexPath)
        return cell
    }

}

我得到的错误告诉我,
numberOfSections、numberofrowsinssection
cellForRowAt
没有覆盖其超类中的任何方法

遵守协议时,只需实现方法体

当您对一个类进行子类化时,您可以
重写该方法

当您使用自定义的
TableViewController
时,由于您不是遵守
UITableViewDataSource
的人,因此您将覆盖
方法,superview(UITableViewController)将被禁用


但是,如果您不是从
UITableViewController
继承,就像您从
UITableViewCell
继承的案例一样,该方法不在超类中,您应该自己实现它。

我不建议在
UITableViewCell
内部使用
UITableView
。我建议您将
UITableView
与具有自定义
UIView
UITableViewCell
一起使用,在该
UIView
中,您将
UICollectionView
与自定义
UICollectionCell

一起使用,因为您是从UITableViewCell继承的,而不是从UITableViewController继承的(在声明函数的地方),只需删除覆盖。如果像这样使用tableView.dataSource=self,您是否有任何错误您是否自己编写了覆盖关键字?删除这些方法,并让xcode自动符合您的协议,即UITableViewDataSource。