iPhone IOS5 Storyboard,如何使用自定义.xib文件加载UIViewController? [英] iPhone IOS5 Storyboard, how to load a UIViewController with a custom .xib file?
问题描述
我有一些来自旧iOS4项目的UIViewControllers,他们使用的是.xib,在界面构建器中创建。
I have some UIViewControllers from my old iOS4 project, they are using .xib, created in interface builder.
我为iOS5构建的新项目使用了故事板。
My new project, built for iOS5, uses storyboards.
我正在尝试将UIViewController添加到故事板,但让它使用我已经拥有的自定义XIB 。我在indentity inspector(在界面构建器中)设置了控制器的标识,但我不确定如何要求该控制器加载自定义.xib。
I'm trying to add a UIViewController to the storyboard, but have it use a custom XIB that I already have. 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.
感谢任何帮助!
PS。到目前为止,我能够通过为故事板目的创建一个包装器类来解决这个问题,并让该类具有另一个UIViewController。但这有点击败了故事板的全部内容。
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. But this kinda defeats the whole point of a storyboard.
推荐答案
您可以将xib的内容复制到故事板中然后实例化它使用:
You could copy the contents of the xib into the storyboard and then instantiate it using:
- (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];
这篇关于iPhone IOS5 Storyboard,如何使用自定义.xib文件加载UIViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!