我使用Xcode 6.我有几个视图控制器连接在一起与现有的Seques(推)。我将初始点设置为导航控制器。我的应用程序根据一种情况加载视图或表视图控制器。我使用编辑器菜单嵌入导航控制器。我可以在运行之前看到导航控制器,但它在运行时消失。有人知道原因吗?
我对applicationdidfinishlaunchwithoption中的代码中的这部分内容产生怀疑导致此问题:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger RegisteredFlagNumber = [defaults integerForKey:@"RegisteredFlag"];
bool isLoggedIn= (RegisteredFlagNumber==1) ? true:false;
NSString *storyboardId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initViewController;
[self.window makeKeyAndVisible];
但我不知道如何修复它?
答案 0 :(得分:0)
您需要在IB处将其设置为Initial ViewController
。
在属性检查器中查找View Controller或Window Controller类别,并设置Is Initial View Controller复选框。
答案 1 :(得分:0)
我找到了答案: 我在applicationdidfinishluchwithoption中以编程方式添加它:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger RegisteredFlagNumber = [defaults integerForKey:@"RegisteredFlag"];
bool isLoggedIn= (RegisteredFlagNumber==1) ? true:false;
NSString *storyboardId = isLoggedIn ? @"MainIdentifier" : @"LoginIdentifier";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//这里是获取结果的更改
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId];
UINavigationController *navigationController=[[UINavigationController alloc]initWithRootViewController:initViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//这里是获取结果的更改
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];