【发布时间】:2018-02-19 08:51:10
【问题描述】:
我的代码是
#import "AppDelegate"
在 viewDidLoad 中
self.delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
得到回复后
//If server response is success make HomeViewController as Root VC
if ([[[_response objectForKey:@"Response"] objectForKey:@"status"] isEqualToString:@"SUCCESS"]) {
dispatch_async(dispatch_get_main_queue(), ^{
//Make root view controller
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; //My storyboard name is Main.storyboard
HomeViewController * hvc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"HVC"];
self.delegate.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:hvc];
[self.delegate.window makeKeyAndVisible];
});
}
但它不起作用......
【问题讨论】:
-
不工作是什么意思?你得到的输出是什么?
-
什么对你不起作用? , 你确定你所有的标识符都是正确的吗?
-
我想设置我的主页是root VC。当我重新打开我的应用程序时,它得到的是登录页面而不是主页
-
@Prashant Tukadiya 是的,所有 id 都是正确的,它正在从登录页面成功移动到主页。重新打开我的应用程序后,它的打开登录页面不是主页,但我的主页是根页面
-
@Marking ,登录后。将布尔变量设置为 UserDefault。现在在 appDelegate 检查 bool 变量是否不是 nil 和 true 然后直接从那里设置 HomeViewController。无需登录视图控制器
标签: ios objective-c uinavigationcontroller pushviewcontroller rootviewcontroller