我正在研究新的iOS 5.0上的故事板。它似乎真的很容易使用和实现,但我的问题是...如何将旧的Xib更新到故事板?
例如。我有一些在没有故事板的情况下开发的类,其中一些类附带了xib文件,可以帮助我快速设置自定义布局。显然,当我使用这种类时,我需要使用initWithNibName:bundle:来实例化它,现在它已经可以使用了,并且我可以根据需要多次使用它,因为布局是在xib中编码的。
现在故事板。storyboard不允许从xib加载视图控制器,并且我没有找到在主Storyboard中加载storyboard文件的方法。似乎每次在新项目中使用特定的视图控制器时,我都需要重新配置它的布局。似乎现在我不得不在每个使用这个控制器的新应用程序中重新配置我的控制器的布局,而不是使用内部有布局的xib文件。
也许有什么是我不明白的。有人能帮我理解使用故事板的最好方法吗?
提前谢谢你。
加布里埃尔。
编辑回复sw3n
多亏了sw3n,也许我理解了。下面的代码可以工作,但是这是完全正确的吗?
// All this code is implemented inside the MyViewController class.
// Attached to an UIButton;
- (void)loadNewController:(id)sender {
[self performSegueWithIdentifier:@"newControllerIdentifier" sender:sender];
}
- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
// As suggested by sw3n
// Load the storyboard from file.
UIStoryboard *storyboardTest = [UIStoryboard storyboardWithName:@"StoryBoardLoad_Test" bundle:nil];
// Instantiate the viewController that live in the storyboard file
UIViewController *destinationViewController = [storyboardTest instantiateViewControllerWithIdentifier:@"newControllerIdentifier"];
// Instantiate a segue to start the chain
UIStoryboardSegue *segue = [[UIStoryboardSegue alloc] initWithIdentifier:identifier source:self destination:destinationViewController];
[self prepareForSegue:segue sender:sender];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"newControllerIdentifier"]) {
[segue.destinationViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
// Are there new options to present the controller?
// If I was in a NavigationController a could obviously push it.
[self presentModalViewController:segue.destinationViewController animated:YES];
}
}
发布于 2011-11-23 09:31:34
这就是你要找的吗?
(UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil
发布于 2012-09-14 05:05:53
听起来有点晚了,但似乎没有答案的结论。您可以使用上面提到的storyboardWithName()。从UIStoryboard创建新的视图控制器,并将新的Viewcontroller挂接到视图层次中所需的位置。你也可以使用多个故事板文件来分割你的UX设计。我写了一些关于如何在我的站点上挂接它作为rootcontroller的东西,但基本上它应该在任何地方都可以工作。
发布于 2011-11-24 18:21:00
接口生成器:
在代码中:
[self performSegueWithIdentifier:@"mySegueNameFromInterfaceBuilder" sender:self];
https://stackoverflow.com/questions/8191342
复制相似问题