我有一个基类:
class BaseViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITableViewDataSourcePrefetching {
var posts = [Post]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "PostTableViewCell", for: indexPath) as? PostTableViewCell else {
fatalError("The dequeued cell is not an instance of PostTableViewCell.")
}
let post = posts[indexPath.row]
cell.parentViewController = self
cell.initialize(post: post)
return cell
}
}
我用作子类:
class FeedViewController: BaseViewController {
@IBOutlet weak var tableView: UITableView!
// Other stuff
}
我使用基类来处理所有表视图功能(我在应用程序的许多部分中都重复使用了。)>
在我的情节提要中,我为FeedViewController
设置了控制器设计,并具有表格视图。但是,我不确定如何将情节提要插座(当前已连接到FeedViewController
)传递给我的基本控制器,以便基本控制器可以处理所有表视图逻辑。我该怎么办?
我有一个基类:BaseViewController类:UIViewController,UITableViewDelegate,UITableViewDataSource,UITableViewDataSourcePrefetching {var posts = [Post]()func tableView(_ ...
如果您不直接在代码中实例化BaseViewController
,则只需在基类中移动插座声明(storyboard将自动处理此声明)