gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:40 25 4
gpt4 key购买 nike

在我的应用程序中,我目前有一个导航 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com