gpt4 book ai didi

ios - 什么时候继承 UITableView?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:50:51 25 4
gpt4 key购买 nike

我有一个 MainViewController,我想向其中添加两个 UITableView,每个都有不同的单元格。但我不想通过检查表委托(delegate)方法来阻塞我的 MainViewController 代码,然后对其进行操作。它变得太乱了。

所以我想我会子类化 UITableView 并让它自己处理 cellForRow 和其他表方法,这样当我想向 MainViewController 添加一个表时,我所要做的就是

CustomTable *customTable = [[CustomTable alloc] init];
[self.view addSubview:customTable];

并且所有委托(delegate)方法都将在该类中处理,让我的 MainViewController 保持整洁。

我是不是处理错了?我应该改为继承 UITableViewController 吗?有什么区别?

最佳答案

什么时候子类UITableView?不是现在。

创建两个类,它们是 View Controller 的成员变量。将 TableView 委托(delegate)指向您的两个新类中的每一个。

在 Cocoa 中,您倾向于组合类,而不是像通常在 Java 和 C# 中那样继承它们。

关于ios - 什么时候继承 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10250060/

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