简体   繁体   English

防止UIViewController从应用程序包中加载过时的XIB

[英]Prevent UIViewController loading stale XIB from app bundle

I have a UIViewController subclass in a shipping app whose UI has historically been loaded from a XIB file. 我在运输应用程序中有一个UIViewController子类,该应用程序的UI历史上是从XIB文件中加载的。

In order to resolve some iOS 7 compatibility problems, I've had to switch to building this screen programatically, hence the XIB is no longer required and I've deleted it from the project and done a clean build in Xcode. 为了解决某些iOS 7兼容性问题,我不得不切换到以编程方式构建此屏幕,因此不再需要XIB,并且已从项目中删除它并在Xcode中进行了干净的构建。

However, when installing the new build over the top of the version on the App Store, I'm ending up with a double UI - it looks like the residual XIB file which will still exists in the app bundle for upgraded versions is getting loaded as well as my programatically-created version. 但是,当在App Store的版本顶部安装新版本时,我得到的是双重UI-看来,将仍然存在于升级包的应用程序捆绑包中的剩余XIB文件将被加载,因为以及我以编程方式创建的版本。

Does anyone know how to stop a UIViewController subclass from loading a stale XIB and only creating the view programatically? 有谁知道如何阻止UIViewController子类加载陈旧的XIB并仅以编程方式创建视图?

I've tried temporarily commenting out the call to [super initWithNibName: nil bundle nil] in my initWithNibName:bundle: implementation (I know this is a bad thing to do - just trying things out to understand the problem better), but this has not helped. 我尝试在initWithNibName:bundle:实现中暂时注释掉对[super initWithNibName: nil bundle nil]的调用(我知道这是一件不好的事,只是想尽办法更好地理解问题),但是没有帮助。

Moving my programatic view creation code from viewDidLoad to loadView solved the problem; 将我的程序化视图创建代码从viewDidLoad移到loadView解决了该问题; it seems implementing this method prevents the runtime from going looking for a XIB to load. 似乎实现此方法使运行时无法寻找要加载的XIB。

Don't use initWithNibName and just create your view like this : 不要使用initWithNibName,而是像这样创建视图:

myViewController = [[MyViewController alloc] init];

Next, in your viewDidLoad you can create all your UI elements programatically. 接下来,您可以在viewDidLoad编程方式创建所有UI元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM