我正在寻找一种方法来改变故事板中的起始视图。我有2个不同的视图,一个用于教程,另一个是应用程序本身。我想在第一次加载应用程序时加载教程,下次它应该只是应用程序本身。我怎么能用代码做到这一点?
答案 0 :(得分:3)
您是尝试从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;
}
答案 1 :(得分:1)
首次启动应用First iPhone Launch和First Launch
时,请检查以下链接当你发现app正在启动第一次加载或推送你的教程ViewController否则根据你的需要加载默认的View控制器。
答案 2 :(得分:1)
使用更少代码执行此操作的方法是创建第三个视图控制器,将其称为根视图,这将始终是第一个加载,然后在此视图中检查
下一个要加载的视图,无论是教程还是应用视图。
为每个视图提供一个故事板ID
调用教程视图:@"tutorialMainView"
和应用视图:@"appMainView"
然后在根视图中,您可以按如下方式加载它:
NSString *viewName = @"tutorialMainView";
UIViewController *tempView = [[UIStoryboard storyboardWithName:@"my_storyboard" bundle:nil] instantiateViewControllerWithIdentifier:viewName];
取决于你之后要做什么,要么推它,要么让它替换当前的rootView(我建议将其设置为新的rootViewController)
答案 3 :(得分:0)
1.转到故事板 2.点击您要先制作的视图 查看此图片并将初始控制器设置为图像