ios - AppDelegate、LoginHome、TabBar 和 HTTP GET 请求

标签 ios objective-c uistoryboard

在我的应用程序中,我当前有一个导航 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 类中设置。

问题:我是否需要将 LoginHomeVCTabBarVC 分开并将 TabBarVC 设置为初始值VC,或者我可以以编程方式模式转到 TabBarVC (推送可能是我丢失按钮等的原因),还是我完全接近这个 LoginHome->TabBar错了?

编辑:解决此问题的最简单方法是什么?

最佳答案

将您的TabBarControl设置为 Root View ,如果用户未登录,则仅显示您的登录 View Controller 模型。

关于ios - AppDelegate、LoginHome、TabBar 和 HTTP GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20877248/

相关文章:

ios - 如何删除 UIViewController?

ios - 未调用第二个 ViewController 中的委托(delegate)方法

objective-c - 可变长度数组声明的解决方法不能有 'static' 错误

iphone - Storyboard - 根据情况自动返回上一屏幕

ios - 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因 : 'Could not load NIB in bundle

iphone - 在 iPhone 5 中自动调整 UIView 的大小

ios - 应用程序被杀死后如何找到用户位置?

objective-c - 最佳实践 : Return mutableArray. 复制或 nsmutableArray 如果返回类型是 NSArray

ios表格单元格左侧细节不是动态大小

ios - 添加第二个 segue 搞砸了位置?