【问题标题】:Changing the start view in storyboard [duplicate]更改情节提要中的开始视图[重复]
【发布时间】:2013-06-28 14:59:10
【问题描述】:
我正在寻找一种方法来更改情节提要中的起始视图。我有 2 个不同的视图,一个是教程,另一个是应用程序本身。我想在第一次加载应用程序时加载教程,下次它应该只是应用程序本身。我怎样才能用代码做到这一点?
【问题讨论】:
标签:
iphone
ios
objective-c
uistoryboard
【解决方案1】:
您是尝试从 nibfile 还是在 AppDelegate 中执行此操作?
在第一种情况下,只需检查标志“是初始视图控制器”。
第二个你必须把你的控制器作为RootViewController,像这样:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options{
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
MenuViewController *menu = [navController.storyboard instantiateViewControllerWithIdentifier:@"MenuController"];
CustomViewController *custom = [navController.storyboard instantiateViewControllerWithIdentifier:@"CustomController"];
// First item in array is bottom of stack, last item is top.
navController.viewControllers = [NSArray arrayWithObjects:menu, custom, nil];
[self.window makeKeyAndVisible];
return YES;
}
【解决方案3】:
用更少的代码做到这一点的方法是创建第三个视图控制器,称之为根视图,它总是第一个加载,然后在这个视图中检查
接下来要加载哪个视图,教程或应用视图。
给每个视图一个故事板 ID
调用教程视图:@"tutorialMainView"
和应用视图:@"appMainView"
然后您可以从根视图中按如下方式加载它:
NSString *viewName = @"tutorialMainView";
UIViewController *tempView = [[UIStoryboard storyboardWithName:@"my_storyboard" bundle:nil] instantiateViewControllerWithIdentifier:viewName];
这取决于你之后做什么,要么推送它,要么让它替换当前的 rootView(我建议将它设置为新的 rootViewController)
【解决方案4】:
1.转到故事板
2.先点击你要制作的视图
看这张图,把初始控制器设置成 image