来自UITabBarController的当前模态视图

时间:2013-01-17 07:59:41

标签: ios uitabbarcontroller storyboard

我使用故事板生成了一个新的选项卡式应用程序。

到目前为止我已经

TabBarController   - > FirstViewController   - > SecondViewController   - > ModalViewController

我正在尝试在显示tabBarController之前打开模态视图。我在AppDelegate.m上添加了以下代码

showModalView

调用

application:didFinishLaunchingWithOptions:;

- (void)showModalView
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    GSLoginViewController *loginView = [storyboard instantiateViewControllerWithIdentifier:@"loginView"];
    [loginView setModalPresentationStyle:UIModalPresentationFullScreen];
    [self.window.rootViewController presentViewController:loginView animated:YES completion:NULL];
}

这里有我的输出:

Warning: Attempt to present <ModalViewController: 0x93670d0> on 
<UITabBarController: 0x935d170> whose view is not in the window hierarchy!

1 个答案:

答案 0 :(得分:5)

你得到的是因为你的Appdelegate不知道tabbarcontroller是你的根视图。你应该尝试这样的事情。

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;

并相应地添加你的代码。事情是你应该让app delegate知道tabbarcontroller是rootviewcontroller。