作者y03131003 (Jimmy)
看板MacDev
标题[问题] storyboard的initial view controller
时间Wed Feb 19 22:42:05 2014
我的界面是用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
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.218.72
1F:推 whitefur:keyWindow.rootViewController = tabbarController 02/20 10:08
2F:→ whitefur:主功能不要用present的了, 因为你不是随时都会回登入画面 02/20 10:10
3F:→ whitefur:直接把整个rootViewController换掉 02/20 10:11
4F:→ y03131003:root改成tabbar 然後在tabbar判断要不要present登入画 02/20 12:20
5F:→ y03131003:面吗? 02/20 12:20
6F:→ howdiun:TabBarViewController新增storyboard ID,直接呼叫他 02/20 15:02
7F:→ whitefur:一开始的rootVC一样是登入, 不需要登入画面的话就把 02/21 10:33
8F:→ whitefur:rootVC换成tabbarController 02/21 10:34
9F:→ whitefur:if(已登入) rootViewController = tabbarController; 02/21 10:34
10F:→ y03131003:感谢,修改rootViewController成功了! 02/21 17:04
11F:→ benck:我觉得你这样好复杂... 02/22 09:50
12F:→ benck:我的做法是,用storyboard直接就拉一个tab view controller 02/22 09:51
13F:→ benck:设成root 02/22 09:51
14F:→ benck:然後在第一个tab的viewdidload里面判断 02/22 09:51
15F:→ benck:如果未登入的话,就present 你的登入modal view 02/22 09:51
16F:→ benck:login的vc也可以在storyboard拉,就更简单了,直接 02/22 09:53
17F:→ benck:performsegue 02/22 09:53
18F:→ y03131003:viewDidLoad里面好像不能执行present的动作 02/23 18:14
19F:→ y03131003:会有whose view is not in the window hierarchy!的错误 02/23 18:14