ios - 无法从 AppDelegate 呈现 View Controller

标签 ios iphone push-notification apple-push-notifications uistoryboard

我需要从应用委托(delegate)中呈现一个 View Controller 。

当收到电话通知时,我可以通过分析“didReceiveRemoteNotification”方法中的“userInfo”来决定应该显示 3 个 View Controller (名为 ForumViewController、BlogViewController 和 NewsViewController)中的哪一个。

但是当我尝试使用 Storyboard或下面的代码呈现适当的 View Controller 时:

self.viewController = [[MembersViewController alloc] initWithNibName:@"MembersViewController" bundle:nil];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];

然后,应用程序给出错误“警告:尝试呈现其 View 不在窗口层次结构中!”。它还会卡在特定的 View Controller 上。

请记住,当应用程序启动时,我试图呈现的 View Controller 不是流程的一部分(流程是 LogoViewController -> SplashViewController -> HomeViewController)。

HomeViewController 和 MembersViewController 本质上是用于公共(public)和私有(private)查看的主菜单页面。在这里我必须向观众展示一些东西。

最佳答案

选择-1

使用推送

 UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
MembersViewController *vc = [navController.storyboard instantiateViewControllerWithIdentifier:@"MembersViewController"];

[navController pushViewController:vc animated:YES];

使用礼物

MembersViewController *root = (MembersViewController *)self.window.rootViewController;
UIViewController *vc = [root.storyboard instantiateViewControllerWithIdentifier:@"MembersViewController"];

[root presentViewController:vc animated:YES completion:NULL];  

已更新

  UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MembersViewController* pvc = [mainstoryboard instantiateViewControllerWithIdentifier:@"MembersViewController"];
[self.window.rootViewController presentViewController:pvc animated:YES completion:NULL];

关于ios - 无法从 AppDelegate 呈现 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38304408/

相关文章:

ios - 如何处理未打开的推送通知(iOS、Swift)

push-notification - CloudKit 不会将我的徽章计数重置为 0

iphone - KVO : Apparently the same "effective" keyPath produce different results

ios - 检索 JSON 对象 Swift 2

ios - 当用户使用长按手势时如何在 Collection View 单元格中显示按钮。

iphone - iOS 部署目标缺失

android - 适用于安卓系统的 FCM : popup system notification when app is in background

ios - 如何在普通 UIView(不是 UIImage)上获得多重混合模式

iphone - 在 iOS 中实现搜索历史功能

滚动时 iPhone UITableView 生涩