从视图控制器调用另一个类(无视图)

发布于 2024-12-22 17:34:00 字数 262 浏览 1 评论 0原文

我正在 XCODE 中创建一个 SQL 项目。我有一个看法。我的主视图控制器正在将数据库加载到表/数组中。我想添加另一个类来处理 UITableView 中表格的显示。因此,我在类文件夹中添加了另一个类,以在参数更改时处理此函数。添加时*.m 文件中没有方法。

我的问题是,如果我在新类中创建自己的方法来创建和填充表,那么应该如何从 MainViewController 类中调用新类?我假设我无法使用“viewDidLoad”或“viewDidAppear”,因为没有实际视图。这是正确的吗?

I am creating an SQL project in XCODE. I have one view. My main view controller is loading the database to a table/array. I want to add another class just to handle the display of the table in a UITableView. So, I added another class to my classes folder to handle this function as parameters change. There were no methods in the *.m file when it was added.

My question is, If I create my own methods int he new class to create and populate the table, how should the new class be called form the MainViewController class? I assume I cannot use 'viewDidLoad' or 'viewDidAppear' because there is no actual view. Is this correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失眠症患者 2024-12-29 17:34:00

为此,建议您应该使用现有的 UITableViewController 模式。

UITableViewControllerUITableView 依赖于 UITableViewDataSource。您的类应该实现 UITableViewDataSource 协议,以将数据输入到 UITableView 中。

我在此线程中起草了一个简单的示例,其中数据来自静态大批。

For this propose your should use the existing UITableViewController pattern.

UITableViewController and UITableView relies on data from an UITableViewDataSource. Your class should implement the UITableViewDataSource protocol to feed data into your UITableView.

I drew up a simple example in this thread, where data comes from an static array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文