从视图控制器调用另一个类(无视图)
我正在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,建议您应该使用现有的 UITableViewController 模式。
UITableViewController
和UITableView
依赖于UITableViewDataSource
。您的类应该实现UITableViewDataSource
协议,以将数据输入到UITableView
中。我在此线程中起草了一个简单的示例,其中数据来自静态大批。
For this propose your should use the existing
UITableViewController
pattern.UITableViewController
andUITableView
relies on data from anUITableViewDataSource
. Your class should implement theUITableViewDataSource
protocol to feed data into yourUITableView
.I drew up a simple example in this thread, where data comes from an static array.