如何在故事板中从appdelegate推送viewcontroller [英] How to push viewcontroller from appdelegate in storyboard

查看:146
本文介绍了如何在故事板中从appdelegate推送viewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 SWRevealViewController ,我想在应用收到通知时打开一个特定的控制器。我尝试了很多解决方案,但没有任何效果。

I am using SWRevealViewController in my project, and I want to open a particular controller when the app receives a notification. I have tried so many solutions but nothing works.

如何从AppDelegate显示特定的ViewController?

How can I show a specific ViewController from my AppDelegate?

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    UIApplicationState appState = UIApplicationStateActive;
    if ([application respondsToSelector:@selector(applicationState)]) {
        appState = application.applicationState;
    }
    application.applicationIconBadgeNumber = 0;
    if (appState != UIApplicationStateActive) {

        SWRevealViewController *navigationController = (SWRevealViewController *)self.window.rootViewController;
        UINavigationController *nav = (UINavigationController *)navigationController;
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
        PushNotificationsVC *controller = (PushNotificationsVC*)[mainStoryboard instantiateViewControllerWithIdentifier: @"PushNotificationsVC"];
        [nav pushViewController:controller animated:YES];

    } else {

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Notification"
                                                            message:[NSString stringWithFormat:@"%@",[[userInfo objectForKey:@"aps"] valueForKey:@"alert"]]
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
        [alertView show];
    }
}


推荐答案

关注此 http://www.appcoda.com/ios-programming-的人通过使用故事板,侧边栏导航菜单/

UIStoryboard *st = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
DestinationController *descController = (DestinationController*)[st instantiateViewControllerWithIdentifier: @"storyboardID_DestController"];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:descController];
SidebarViewController *rearViewController = (SidebarViewController*)[st instantiateViewControllerWithIdentifier: @"storyboardID_SidebarMenu"];

RevealViewController *mainRevealController = [[SWRevealViewController alloc]  init];

mainRevealController.rearViewController = rearViewController;
mainRevealController.frontViewController= frontNavigationController;

self.window.rootViewController = mainRevealController;

希望能帮到别人...

Hope it help someone else...

这篇关于如何在故事板中从appdelegate推送viewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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