子类化您自己的类之一还是使用相同的父类?

发布于 2024-12-09 21:15:33 字数 510 浏览 7 评论 0原文

在我的应用程序中,我有一个 mainViewController,其中有一堆字母平铺 UIImageView。您可以在此 mainViewController 上平移字母来拼出单词。

我还有包含字母图块的弹出视图控制器,您可以将其拖到 mainViewController 上。将字母图块拖放到 mainViewController 上后,它们需要访问 mainViewController 上已存在的字母图块所执行的所有相同方法。

目前,我分别在 mainViewController 和弹出视图控制器中创建字母图块。 mainViewController 和 popover viewcontroller 的父类都是 UIViewController。

我想知道在我的情况下,我是否应该在 mainViewController 类中声明弹出视图控制器中包含的所有字母图块,然后让 popoverview 控制器成为 mainViewController 的子类?

如果我应该改变它,你能告诉我为什么这样做会更好吗?

谢谢!

In my application, I have a mainViewController that has a bunch of letter tile UIImageViews. You can pan the letters around on this mainViewController to spell out words.

I also have popover viewcontrollers that contain letter tiles that you can drag out onto the mainViewController. Once the letter tiles are dropped onto the mainViewController, they need to have access to all the same methods that the letter tiles do that already exist on the mainViewController.

Currently, I create the letter tiles in the mainViewController and the popover viewcontrollers separately. Both the mainViewController and popover viewcontroller's parent classes are UIViewController.

I was wondering if in my situation, I should be declaring all letter tiles contained in my popover viewcontrollers in the mainViewController class, then have the popoverview controllers be a subclass of mainViewController?

If I should change it, can you please tell me why it would be better to?

Thanks!

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

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

发布评论

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

评论(1

冰雪梦之恋 2024-12-16 21:15:33

Objective-C 因更喜欢委托而不是子类而闻名。

我宁愿使用一个了解所有图块及其方法的数据源类,并在两个控制器中使用它。

Objective-C is famous for preferring delegation over subclassing.

I would rather use a datasource class that knows of all the tiles and their methods and use it in both controllers.

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