2013-01-17 48 views
0

我已经使用故事板生成了一个新的选项卡式应用程序。从UITabBarController提供模态视图

到目前为止,我有

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! 
+0

你可以在[这里] [1]找到答案。 [1]:http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy –

回答

5

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

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

并相应地添加您的代码。事情是,您应该让应用程序委托知道tabbarcontroller是rootviewcontroller。