在我的应用程序中,我当前有一个导航 Controller 作为初始 View Controller 。这个 NavigationController 通过以下方式链接我的应用程序,其中 NC=NavigationController,VC=ViewController,TC=TabBarController:
NC->LoginHomeVC->TC->(rest of app)
我读到 TabBarViewController 必须是 Root View Controller (我认为这并不意味着它必须是“初始 VC”) 在我的 AppDelegate.m 的 didFinishLaunchingWithOptions 方法中,我有以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://myurl.com/xxx/xxx"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];
[request setHTTPMethod:@"GET"];
NSError *requestError;
NSURLResponse *urlResponse = nil;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&requestError];
NSString* result = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
if([result isEqualToString: @"logged"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"TabBarControl"];
[(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];
NSLog(@"It's hitting log");
}
else if([result isEqualToString: @"notlogged"])
{
//do nothing
NSLog(@"It's hitting notlog.");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"JumpToLogin"];
[(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];
}
NSLog(@"%@", result);
return YES;
}
因此,我的条件只是检查用户是否已登录,如果已登录,则将其带到 TabBarViewController
,如果没有,则将其带到 LoginHomeViewController
。目前,我的“logged”代码发起了对 TabBarController
的推送。另外,我的 LoginHomeVC
模式上的登录按钮也会转到 TabBarController
。当推送执行时,我的 TabController
初始 View 上的 NavController
会丢失颜色和按钮等所有内容,所有这些都在我的 TC 的初始 VC 类中设置。
问题:我是否需要将 LoginHomeVC
与 TabBarVC
分开并将 TabBarVC
设置为初始值VC,或者我可以以编程方式模式转到 TabBarVC
(推送可能是我丢失按钮等的原因),还是我完全接近这个 LoginHome->TabBar
错了?
编辑:解决此问题的最简单方法是什么?
最佳答案
将您的TabBarControl设置为 Root View ,如果用户未登录,则仅显示您的登录 View Controller 模型。
关于ios - AppDelegate、LoginHome、TabBar 和 HTTP GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20877248/