在 Objective-C 中组织头文件的正常方式是什么?

发布于 2024-09-18 16:29:53 字数 415 浏览 5 评论 0原文

我确实以最好的意图开始组织我的 .h 文件,但不知怎的,它们变得令人厌恶的混乱。

下面是一个例子(这并不是那么坏,但我见过更糟糕的!)。我尝试过使用 #pragma mark 对部分进行分组,但看起来似乎更混乱。

所有 UILabels 和 UIButton 都是必需的(如上所述),因为它们显示来自 Web 服务请求的数据,因此如果我们使用 Interface Builder 设计 GUI,则它们都是必需的。例如,标签可能是产品的“重量”或“高度”特征。

对于如何以最可维护/可读的方式组织这些内容,有人有什么好的建议吗?

干杯

alt text

I do start off organising my .h files with the best intentions but somehow they get disgustingly messy.

Below is an example (which isn't that bad, but i've seen much worse!). I've tried grouping sections with #pragma mark but it seems to look even messier.

All the UILabels and UIButtons are required (as mentioned above) as they're showing data coming from a web service request so they're all required if we're using Interface Builder to design our GUI's. For example, the label might be a "weight" or "height" characteristic for a product.

Does anyone have any good advice on how to organise these in the most maintainable/readable way?

Cheers

alt text

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

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

发布评论

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

评论(1

别挽留 2024-09-25 16:29:53

我觉得你可能拥有太多的财产。我确实从未见过有这么多插座的课程;为什么要处理布局中的每个元素?为什么全部来自一个控制器?

似乎解决您的问题的最佳方法是考虑您的班级并将其分成多个班级;每个控制界面的一个方面。您还需要确保您确实需要解决所有这些要素。 (尤其是 UILabelUIButton 看起来像是有出口的奇怪东西。)

It strikes me as possible that you have too many properties, there. I've quite literally never seen any class with this many outlets; why are you addressing every single element in your layout? And why all from one controller?

It seems as if the best solution to your problem is to consider your class and split it up into multiple classes; each controlling one aspect of your interface. You also need to make sure that you really need to address all these elements. (The UILabels and UIButtons in particular seem like strange things to have outlets for.)

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