iOS:IBOutlet 的替代品?

发布于 2024-11-08 19:41:33 字数 215 浏览 0 评论 0原文

我有很多非常巨大的视图控制器。事实上,有很多无用的代码:

InterfaceBuilder 中每个视图的属性

在 dealloc 中合成

和释放,

我想可能可以将它们全部(我需要的所有视图)收集起来。但在这种情况下我不会有任何 IBOutlet。如何将他们与IB联系起来?

你能帮助我吗?我真的不喜欢有 3 个地方有如此相似的代码=(

I've got a lot of really huge viewControllers. In fact there's a lot of useless code:

property for each view from InterfaceBuilder

synthesize

and release in dealloc

I'm thinking may be it is possible to have them all (all views that I need) in collection. But I won't have any IBOutlet in this case. how to connect them with IB?

Can you help me? I really don't like when there's 3 places with so similar code=(

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

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

发布评论

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

评论(1

晨曦慕雪 2024-11-15 19:41:33

您可以使用 IBOutletCollection,但通常应该在您使用非常相似的对象(例如,状态需要一起更改的多个按钮)时保留这些集合。我会认真地重新考虑尝试重写您的代码以使用可能会使您的工作变得更加困难的东西。

但老实说,您不应该真正担心设置和拆除视图所需的代码行。如果您不喜欢查看这些代码部分,则可以折叠它们。这些将成为您编写的 Obj-C 图形应用程序的标准。考虑一下,如果其他人需要从您中断的地方继续处理您的应用程序,那么他们需要花费更长的时间来找出 IBOutletCollections,而不是为每个部分使用单独的 IBOutlet用户界面的。

You could use an IBOutletCollection, but generally those should be reserved for when you are using very similar objects (e.g. several buttons whose state needs to change together). I would seriously reconsider trying to rewrite your code to use something that could potentially make your job harder down the road.

Honestly though, you shouldn't really worry about the lines of code you need for setting up and tearing down the view. You could just collapse those sections of code if you don't like looking at them. These are going to be standard for Obj-C graphical apps you write. Consider that if someone else needed to pick up work on your application where you left off, it would take longer for them to figure out the IBOutletCollections vs using separate IBOutlets for each piece of the UI.

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