0

好的,所以我一直在寻找以下问题的答案:当推送通知从 AppDelegate 到达时,如何将某个视图控制器推送到视图中?

大多数答案是,如果 rootViewController 是 UINavigationController,我必须通过我的 StoryBoard 实例化一个视图并使用该根导航控制器推送它。

这是我的情况。这是我的故事板的组织方式:

在此处输入图像描述

所以你看到我的 rootViewController 没有 UINavigationController。那么,我该如何将某个视图从我的故事板中推出呢?

注意:为推送通知提供一些单独的模式视图并不是一个好主意。这是我最后的手段。

我想要 Apple Mail 和 Message 应用程序中的解决方案。

4

1 回答 1

0

好吧,我想我不会轻易放弃 :) 这是我找到的解决问题的方法。由于我从模态视图控制器中呈现我的主要应用程序视图,这就是我所做的:

从 iOS 5 开始,每个视图控制器都有一个presentedViewController属性。一旦你知道了,从那里开始就很容易了。这是 AppDelegate.m 中的一些特定代码

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {  
   if ([[userInfo objectForKey:@"notificationType"] isEqualToString: @"messageType"])   {

   UITabBarController * tabBarController = (UITabBarController *)[self.window.rootViewController presentedViewController];
[tabBarController setSelectedIndex:kChatViewIndex]; 
// My view controller that I presented modally is a tabBar, your case can be different. 

// ... so from here I can reach any navigation controller or any other view from inside my app

}

现在既然你已经有了你的视图控制器,你可以使用 setSelectedIndex: 如果它是一个 tabBarController,或者如果它是一个导航单元则推送某个视图控制器。

希望这可以帮助任何有类似问题的人。干杯!

于 2013-04-23T10:41:13.967 回答