gpt4 book ai didi

ios - 将 Storyboard 导出传递给基本 Controller 类

转载 作者:行者123 更新时间:2023-12-01 21:58:44 24 4
gpt4 key购买 nike

我有一个基类:

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
}

我使用基类来处理所有的表格 View 函数(我在我的应用程序的许多部分重用了这些函数)。

在我的 Storyboard中,我为 FeedViewController 设置了 Controller 设计。 ,带有表格 View 。但是,我不确定如何通过我的 Storyboard socket ,该 socket 目前连接到 FeedViewController。到我的基本 Controller ,以便基本 Controller 处理所有 TableView 逻辑。我该怎么做?

最佳答案

如果不实例化 BaseViewController直接在代码中,然后只需在基类中移动导出声明( Storyboard将自动处理)

class BaseViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITableViewDataSourcePrefetching {
@IBOutlet weak var tableView: UITableView!

// Other stuff
}

class FeedViewController: BaseViewController {

// Other stuff
}

关于ios - 将 Storyboard 导出传递给基本 Controller 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60763336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com