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。