简体   繁体   English

iPhone IOS5 Storyboard,如何使用自定义.xib文件加载UIViewController?

[英]iPhone IOS5 Storyboard, how to load a UIViewController with a custom .xib file?

I have some UIViewControllers from my old iOS4 project, they are using .xib, created in interface builder. 我有一些来自旧iOS4项目的UIViewControllers,他们使用的是.xib,在界面构建器中创建。

My new project, built for iOS5, uses storyboards. 我为iOS5构建的新项目使用了故事板。

I'm trying to add a UIViewController to the storyboard, but have it use a custom XIB that I already have . 我正在尝试将UIViewController添加到故事板,但让它使用我已经拥有的自定义XIB I've set the controller's identity in the indentity inspector (in interface builder), but am not sure how to ask that controller to load a custom .xib. 我在indentity检查器中设置了控制器的标识(在界面构建器中),但我不确定如何要求该控制器加载自定义.xib。

Any help is appreciated! 任何帮助表示赞赏!

PS. PS。 Up to date I was able to get around this by creating a "wrapper" class for the storyboard purposes, and have that class have another UIViewController. 到目前为止,我能够通过为故事板目的创建一个“包装器”类来解决这个问题,并让该类具有另一个UIViewController。 But this kinda defeats the whole point of a storyboard. 但这有点打败了故事板的全部要点。

You could copy the contents of the xib into the storyboard and then instantiate it using: 您可以将xib的内容复制到storyboard中,然后使用以下方法对其进行实例化:

- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier

after setting the identifier on it. 在设置标识符后。 If you need the instance of the storyboard you can get it this way: 如果你需要故事板的实例,你可以这样得到它:

[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

Mike K's answer is false. Mike K的回答是错误的。

While mixing XIBs and Storyboards doesn't really solve Alex's problem, it is quite possible to do within the same project. 虽然混合XIBs和故事并没有真正解决亚历克斯的问题, 可能在同一项目内完成。

See: https://stackoverflow.com/a/8516479/1309238 re: loading a second storyboard. 请参阅: https//stackoverflow.com/a/8516479/1309238 re:加载第二个故事板。

I'm not sure if including a "Main Storyboard" in your Target Summary is advisable if you plan to do this, but if you've loaded a XIB instead of a storyboard to begin with, you can modify the code linked above to load the storyboard after the XIB. 我不确定如果您计划在目标摘要中包含“主要故事板”是可取的,但如果您已经加载了XIB而不是故事板,则可以修改上面链接的代码以加载XIB之后的故事板。

I'm not sure if you can jump into the middle of a storyboard from a XIB, which may have been what Mike meant. 我不确定你是否可以从XIB跳到故事板的中间,这可能是迈克的意思。

你不能在你的项目中混合xib和故事板 - 这是另一个,我害怕。

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

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