0

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

到目前为止我有

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!
4

1 回答 1

5

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

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

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

于 2014-01-24T09:02:29.000 回答