在appdelegate中呈现多个模态视图 [英] present more than one modalview in appdelegate

查看:161
本文介绍了在appdelegate中呈现多个模态视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在应用程序收到的每个推送消息之后呈现一个modalviewcontroller:应用程序:( UIApplication *)应用程序didReceiveRemoteNotification:(NSDictionary *)userInfo

I want to present a modalviewcontroller after every push-message the app recieves in "application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo"

I像这样呈现viewcontroller:

I present the viewcontroller like this:

ReleaseViewController *viewController = [[ReleaseViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window.rootViewController presentModalViewController:navController animated:YES];

因此,当另一个推送消息到来且旧的ModalViewController仍然可见时,我想呈现一个新的modalviewcontroller过去了。但它不起作用。没有发生任何事情,控制台只是说(我认为它是iOS 6 Beta的调试消息):

So when another push-message arrives and the old ModalViewController is still visibile, I want to present a new modalviewcontroller over the old. But it doesn't work. Nothing happened and the console just says (I think it's a debug-message of iOS 6 Beta):

Warning: Attempt to present <UINavigationController: 0x1dde6c30> on <UINavigationController: 0x1dd73c00> whose view is not in the window hierarchy!

我做错了什么?

PS:我不想解雇旧的ViewController,我希望它们能够堆叠。

PS: I don't want to dismiss the old ViewController, I want them to stack.

谢谢!

推荐答案

您可以获得视图控制器的顶部,然后从该顶视图控制器呈现一个新模态

You can get top of your view controllers, then present a new modal from that top view controller

- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
    if (rootViewController.presentedViewController == nil) {
        return rootViewController;
    }

    if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) {
        UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
        UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
        return [self topViewController:lastViewController];
    }

    UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
    return [self topViewController:presentedViewController];
}

你可以用rootViewController调用这个方法是window的rootViewController

You can call this method with rootViewController is window's rootViewController

这篇关于在appdelegate中呈现多个模态视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆