我有一个 View Controller (TableViewController.swift),它继承自一个基本 View Controller (BaseViewController.swift),如下所示:-
class TableViewController: BaseViewController {
// Some code
}
我想在我的 TableViewController 上创建一个 TableView ,但要做到这一点,您必须从 UITableViewController 继承,但我不能这样做,因为 Swift 不允许多重继承;有办法解决这个问题吗?我是 Swift 的新手。
最佳答案
tableView 只是下面的一个 View ,您可以将它添加到您想要的任何 View Controller 中。
另一方面,tableViewController 是带有内置 tableView 的 viewController。
只有当您想更改其当前功能或外观时,您才不需要子类化 tableView。
只需在您的 View Controller 中添加一个 TableView ,并通过实现其所需的方法(numberOfSections、numberOfRows 和 cellForRow..)来遵守 UITableViewDataSource 协议(protocol)。
如果您需要知道何时点击单元格或在 tableView 上执行其他操作,您还应该遵守 UITableViewDelegate 协议(protocol)。
关于ios - 当 View Controller 已经从基础 View Controller 继承时,如何在 View Controller 上创建 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57668903/