[英]How to force interface builder (storyboard) to generate controller initialisation code?
I am getting incredibly frustrated with interface builder at the moment, and would appreciate some help before I ragequit it and code everything by hand (which seems to be much, much, much easier). 目前,我对接口生成器感到非常沮丧,在我对它进行修改和手工编写所有代码之前,希望能获得一些帮助(这似乎非常容易得多)。
The basic situation is this: I need to make a model variable accessible to each view controller in my application. 基本情况是这样的:我需要使应用程序中的每个视图控制器都可以访问模型变量。
The simplest way I can see to do this is to just create a property on the view controllers that retains the model, and to set that after the controller is initialised. 我看到的最简单的方法是在视图控制器上创建一个保留模型的属性,并在控制器初始化后对其进行设置。
However, I can't find any of the actual initialisation code for the views shown on the storyboard in my project. 但是,我找不到项目中故事板上显示的视图的任何实际初始化代码。 There's no reference to any of them at all.
根本没有任何提及。 Does the interface builder really generate not generate any code reference to its controllers in the app delegate?
接口构建器是否真的在应用程序委托中不生成对其控制器的任何代码引用?
For that matter, why is there no reference to any of the top level controller objects (tabview, tableview etc) in code at all? 因此,为什么在代码中根本没有引用任何顶级控制器对象(选项卡视图,表视图等)?
All I want to know is how to force xcode to actually generate the controller creation code in AppDelegate.m - so that I have access to the created instance of the controller - or, failing that, a way to share the model between these amorphous objects. 我想知道的是如何强制xcode在AppDelegate.m中实际生成控制器创建代码-以便我可以访问控制器的已创建实例-否则,将无法在这些无定形对象之间共享模型。
You will need to manually create a subclass of your view controller and then override the methods you want to inject code into. 您将需要手动创建视图控制器的子类,然后覆盖要向其中注入代码的方法。 In Interface Builder you can then choose to make your View controllers of this custom type.
然后,您可以在Interface Builder中选择使这种自定义类型的View控制器成为可能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.