简体   繁体   English

如何从.XIB加载UIViewController?

[英]How to Load A UIViewController From A .XIB?

HI I have a app where I want to load a UIViewController from a .xib file, called ImageViewController. 嗨,我有一个应用程序,我想从一个名为ImageViewController的.xib文件中加载UIViewController。

在此处输入图片说明

I have created the .h and .m files for ImageViewController. 我已经为ImageViewController创建了.h和.m文件。 I have declared a IBOutlet to it in the Application delegate. 我已经在应用程序委托中为其声明了IBOutlet。

I have on many occasions dragged and dropped a UIView (for example) and it is usually initialised by the nib. 我在很多情况下都拖放过一个UIView(例如),它通常是由笔尖初始化的。 As there is a UIViewController object in IB I assume you must be able to do the same. 由于IB中有一个UIViewController对象,因此我假设您必须能够执行相同的操作。 If so what method is called in the UIViewController? 如果是这样,则在UIViewController中调用什么方法? For example I know awakeFromNib is called in a view. 例如,我知道awakeFromNib在视图中被调用。

Cheers In advanced 加油打气

The way to do it is to use awakeFromNib. 做到这一点的方法是使用awakeFromNib。 It appears that it is part of the NSObject UIKit Additions References, not a UIView method. 看来它是NSObject UIKit Additions References的一部分,而不是UIView方法。 There for you should be able to use it for all classes you are instantiating from the nib. 在那里,您应该可以将其用于从笔尖实例化的所有类。

Easy when you know how. 当您知道如何时就很容易。

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

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