UIViewController的initWithNibName:这个设计背后的原因是什么? [英] UIViewController's initWithNibName: a reason behind this design?

查看:130
本文介绍了UIViewController的initWithNibName:这个设计背后的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倾向于同意Joe Conway和Aaron Hillegass的分析,如Ole Begemann今天在 http://oleb.net/blog/2012/01/initWithNibName-bundle-breaks-encapsulation/

I tend to agree with Joe Conway’s and Aaron Hillegass’s analysis, as reported today by Ole Begemann in http://oleb.net/blog/2012/01/initWithNibName-bundle-breaks-encapsulation/

基本上,声明NIB的文件名是相应的UIViewController类的实现细节,并且它不是调用类在init方法中传递NIB文件名的业务。

Basically, they state that the NIB's filename is an implementation detail of the corresponding UIViewController class, and that it is not the business of the calling class to pass in the NIB's filename in the init method.

我想知道这个设计选择是否有任何特殊的原因来自AppKit / UIKit的创建者,或者如果它只是一个错误 - 而在后一种情况下,为什么当UIKit出来时它不会被纠正,这本来是一个好机会。

I was wondering if there was any particular reason for this design choice from the creators of AppKit/UIKit, or if it is merely a mistake — and, in the latter case, why it wasn't corrected when UIKit came out, which would have been a good opportunity.

如果任何Objective-C的旧计时器可以提供这个的历史背景,这将是很好,以便更好地了解我们每天使用的框架。

If any Objective-C old-timer could provide the historical background to this, that would be nice to get a better understanding of the framework we use every day.

推荐答案

今天我想到的是,故事板恰恰是对这个问题的回应。因为故事板是在应用程序级定义的,没有更多的违反封装,只是级别的更改。 UIViewController子类成为故事板作为一个整体的详细实现。

It has come to my mind today that maybe Storyboards are precisely a response to that issue. Because Storyboards are defined at application-level, there is no more violation of encapsulation, merely a change of level. UIViewController subclasses become the detail implementation of the Storyboard as a whole.

它仍然不能解释原始设计背后的历史原因,但至少他们已经做了一些事情来解决这个问题 - 和苹果一样,非常优雅的方式。

It still doesn't explain the historical reasons behind the original design, but at least they have done something to address the issue — and, as often with Apple, in a very elegant way.

这篇关于UIViewController的initWithNibName:这个设计背后的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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