我的界面是用storyboard拉的
第一个页面是登入页面
登入完会进入一个TabBarViewController
我希望只要登入过后
下次开启app的时候跳过登入页面
直接进入TabBarViewController
所以我在登入页面写了以下程式
- (void)viewWillAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (已登入)
{
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
TabBarViewController *tabVC = [sb instantiateViewControllerWithIdentifier:
@"TabBar"];
[self presentViewController:tabVC animated:NO completion:nil];
}
}
这样去跑会有错误
whose view is not in the window hierarchy!
原因是presentViewController一定要在viewDidAppear之后呼叫
所以我把程式码移到viewDidAppear
不过这样的话,登入页面还是会出现一瞬间,才present我的TabBarViewController
请问要怎么做才能让登入页面完全不要出现呢?
有想到一个做法是把登入页面的所有元件先隐藏..没有登入才显示
但总觉得应该有更好的做法XD
keyWindow.rootViewController = tabbarController主功能不要用present的了, 因为你不是随时都会回登入画面直接把整个rootViewController换掉
root改成tabbar 然后在tabbar判断要不要present登入画面吗?
作者:
howdiun (Howdiun)
2014-02-20 15:02:00TabBarViewController新增storyboard ID,直接呼叫他
一开始的rootVC一样是登入, 不需要登入画面的话就把rootVC换成tabbarControllerif(已登入) rootViewController = tabbarController;
感谢,修改rootViewController成功了!
作者:
benck (小伦)
2014-02-22 09:50:00我觉得你这样好复杂...我的做法是,用storyboard直接就拉一个tab view controller设成root然后在第一个tab的viewdidload里面判断如果未登入的话,就present 你的登入modal viewlogin的vc也可以在storyboard拉,就更简单了,直接performsegue
viewDidLoad里面好像不能执行present的动作会有whose view is not in the window hierarchy!的错误