繁体   English   中英

来自UITabBarController的当前模态视图

[英]Present Modal View from UITabBarController

我已经使用情节提要生成了一个新的选项卡式应用程序。

到目前为止,我有

TabBarController-> FirstViewController-> SecondViewController-> ModalViewController

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

showModalView是从application:didFinishLaunchingWithOptions:;调用的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!

之所以会这样,是因为您的Appdelegate不知道tabbarcontroller是您的根视图。您应该尝试这样的操作。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM