在 Objective-C 中组织头文件的正常方式是什么?
我确实以最好的意图开始组织我的 .h
文件,但不知怎的,它们变得令人厌恶的混乱。
下面是一个例子(这并不是那么坏,但我见过更糟糕的!)。我尝试过使用 #pragma mark
对部分进行分组,但看起来似乎更混乱。
所有 UILabels 和 UIButton 都是必需的(如上所述),因为它们显示来自 Web 服务请求的数据,因此如果我们使用 Interface Builder 设计 GUI,则它们都是必需的。例如,标签可能是产品的“重量”或“高度”特征。
对于如何以最可维护/可读的方式组织这些内容,有人有什么好的建议吗?
干杯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我觉得你可能拥有太多的财产。我确实从未见过有这么多插座的课程;为什么要处理布局中的每个元素?为什么全部来自一个控制器?
似乎解决您的问题的最佳方法是考虑您的班级并将其分成多个班级;每个控制界面的一个方面。您还需要确保您确实需要解决所有这些要素。 (尤其是
UILabel
和UIButton
看起来像是有出口的奇怪东西。)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
UILabel
s andUIButton
s in particular seem like strange things to have outlets for.)