我正在寻找一种方法来更改情节提要中的起始视图。我有 2 个不同的视图,一个是教程,另一个是应用程序本身。我想在第一次加载应用程序时加载教程,下次它应该只是应用程序本身。我怎样才能用代码做到这一点?
问问题
739 次
4 回答
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;
}
于 2013-07-01T13:24:49.453 回答
1
首次启动应用程序时检查这些链接 首次 iPhone 启动 和首次启动
当您发现应用程序正在启动第一次加载或推送您的教程 ViewController 时,请根据您的需要加载您的默认视图控制器。
于 2013-07-01T13:23:17.267 回答
1
使用更少代码的一种方法是创建第三个视图控制器,称为根视图,它将始终是第一个加载的视图,然后在此视图中检查
接下来要加载哪个视图,教程或应用程序视图。
给每个视图一个故事板 ID
调用教程视图:@"tutorialMainView"
和应用程序视图:@"appMainView"
然后从根视图中,您可以按如下方式加载它:
NSString *viewName = @"tutorialMainView";
UIViewController *tempView = [[UIStoryboard storyboardWithName:@"my_storyboard" bundle:nil] instantiateViewControllerWithIdentifier:viewName];
之后做什么取决于你,要么推送它,要么让它替换当前的 rootView(我建议将它设置为新的 rootViewController)
于 2013-07-01T13:31:17.740 回答
0
1.转到情节提要 2.单击您要首先查看此图片的视图并设置初始控制器,就像它在图像中一样
于 2013-07-01T14:00:04.810 回答