如何设计code架构时,重叠的对象是否存在? [英] How to design code architecture when overlapping objects exist?

查看:103
本文介绍了如何设计code架构时,重叠的对象是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1个主屏大师(MVC)和4个共享〜图形对象的80%,其他屏幕。他们在一些标签文本,用行动按钮和其他约20%的图形有所不同。在干净的面向对象的code结构方面的思考,我已经开始实施这些屏幕作为单独UIViewControllers。但我不喜欢有指针的4 MVCS以及一些方法重复,所以我rewrited的code为一体的UIViewController。大多数的图形对象是,我把与Interface Builder中的UIImageViews。所以,现在统一的UIViewController的厦门国际银行文件是有点臃肿重叠的那些4画面中的对象。我也需要有像showScreen1,hideScreen2,showScreen2,hideScreen2等方法这些方法,所以我不是很满意这个架构了。我知道我不应该混的4 MVCS(屏幕)和两个code和厦门国际银行的文件将是更清洁的,但我也对性能的事情,节省内存负载等什么是对你的看法?多少内存资源,需要单独的UIViewController的加载?也许相比于code清洁时保存内存量是不值得?同样,有4个独立的MVC的会强迫我有4个三分球都与我的师父MVCS和我的主人MVC 4指向那些独立的MVCS,因为我需要进行沟通,这些屏幕之间导航。另一个选择是使用通知代替的指针,但它不会改变所需关系的量。所以,请分享你的想法和见解:)

I have 1 main Master screen (MVC) and 4 other screens that share ~80% of graphic objects. They differ in some label texts, a button with action and some other 20% graphics. Thinking in terms of clean object oriented code architecture, I have started to implement those screens as separate UIViewControllers. But I didn't like having pointers to those 4 MVCs and a duplication of some methods, so I rewrited the code into one UIViewController. Most of graphic objects are UIImageViews that I put on with Interface Builder. So, now the xib file of that "unified" UIViewController is a little bit bloated with overlapping objects from those 4 screens. I also need to have those methods like showScreen1, hideScreen2, showScreen2, hideScreen2, and other methods, so I'm not very happy with this architecture too. I understand that I should not mix those 4 MVCs (screens) and both the code, and xib files would be cleaner but I'm also thing about performance, saving memory loads and etc. What would be your opinions on that? How much memory resources takes the loading of separate UIViewController? Maybe the amount of saved memory is not worth when compared to code cleanness? Again, having 4 separate MVC's would force me to have 4 pointers both to my Master MVCs and 4 pointers to those separate MVCs from my Master MVC, because I need to communicate and navigate between those screens. Another option would to use notifications instead of pointers but it doesn't change the amount of required relations. So please share your thoughts and insights :)

推荐答案

有关共享相同的设计或许你可以使用类别的用户界面控件,这是我在一个项目正在做。我添加了一个类别,UINavigationBar的显示栏上的质感,增加了一个类别的UIBarButtonItem / UIButton的一个回&安培;取消按钮,因为我ViewControllers都有着相同的背景图片我已经创建了一个包含默认背景图片UIViewController子类 - 在我的应用程序使用的每个视图控制器从这个默认的视图控制器继承

For user interface controls that share the same design perhaps you could use categories, this is what I'm doing in a project. I've added a category to UINavigationBar to show a texture on the bar, added a category to UIBarButtonItem / UIButton for a back & cancel button and since my ViewControllers all share the same background image I've created a UIViewController subclass that contains the default background image - every view controller used in my app inherits from this default view controller.

我会坚持每屏1视图控制器。

I would stick with 1 view controller per screen.

苹果不建议创建巨大的笔尖,<一个href=\"https://developer.apple.com/itunes/?destination=adc.apple.com.8266478284.08266478290.8365294543?i=1970869901\"相对=nofollow>这是在故事板的WWDC 2011的视频尤为明显(看看这个视频,如果你是一个注册的苹果开发)。巨碎粒是在性能方面差,需要花费大量的时间来加载从笔尖停留所有对象和所有对象在内存中的所有时间,即使对象是目前不能被显示在屏幕上。这是一个更好的办法让每个屏幕单独笔尖。

Apple doesn't recommend creating giant nibs, this is especially visible in the WWDC 2011 video on storyboarding (check this video out if you're a registered Apple developer). Giant nibs are bad in terms of performance, it takes a lot of time to load all objects and all the objects from the nib stay in memory all the time, even if the objects are on a screen that's currently not being displayed. It's a better approach to have a separate nib per screen.

这篇关于如何设计code架构时,重叠的对象是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆