我的 AppDelegate.m 中的viewDidFinishLaunchingWithOptions:
方法中包含此代码,结果只是我的 HTTP GET请求响应,而我的手动设置UITabBarViewController (使用指针)作为初始视图控制器。
我想要做的就是在用户未登录的情况下,让我的LoginHomeViewController在启动时成为rootViewController。我需要做些什么来实现这一目标?我是否需要将TabBar的状态重新设置为rootViewController?
if([result isEqualToString: @"log"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivcTabBar = [storyboard instantiateViewControllerWithIdentifier:@"TabBarControl"];
[(UITabBarController*)self.window.rootViewController presentViewController:ivcTabBar animated:NO completion:nil];
NSLog(@"It's hitting log");
}
else if([result isEqualToString: @"notlog"])
{
[(UITabBarController*)self.window resignFirstResponder];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivcLoginHome = [storyboard instantiateViewControllerWithIdentifier:@"LoginHomeStart"];
[(UINavigationController*)self.window.rootViewController presentViewController:ivcLoginHome animated:NO completion:nil];
NSLog(@"It's hitting notlog.");
}
bug:目前它正在登录我,即使它遇到notlog,并在调试器中给出错误说:警告:尝试在UITabBarController上显示UINavigationController,其视图不在窗口层次结构!
编辑: * 更改了“notlog”代码 *
else if([result isEqualToString: @"notlog"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *ivcTabBar = [storyboard instantiateViewControllerWithIdentifier:@"TabBarControl"];
UIViewController *vcLoginHome = [storyboard instantiateViewControllerWithIdentifier:@"LoginHome"];
[ivcTabBar presentViewController:vcLoginHome animated:NO completion:nil];
NSLog(@"It's hitting notlog.");
}
答案 0 :(得分:1)
在tabBarController上显示loginViewController
if([result isEqualToString: @"notlog"])
{
[tabBarCOntroller presentViewController:@"Your Login View Controller" animated:YES completion:nil];
}
并在登录后从内部退出loginViewController