2014-03-26 5 views
12

Я использую в моем проекте SWRevealViewController, и я хочу открыть конкретный контроллер, когда приложение получает уведомление. Я пробовал так много решений, но ничего не работает.Как нажимать viewcontroller из appdelegate в раскадровке

Как я могу показать определенный ViewController из своего 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]; 
    } 
} 
+0

Вы должны прочитать [FAQ] (http://stackoverflow.com/help/ по теме), чтобы задать хорошие вопросы. – rdurand

+0

У меня есть меню слайдов в моем проекте, потому что у меня есть компонент SWRevealViewController. И когда я получаю push-уведомление, я хочу открыть конкретный экран (ViewController). Я не могу открыть конкретный контроллер из appdelegate. (ApplicationDidReceiveNotification). Вы получаете то, что я пытаюсь сказать? – user3436439

+0

Если у вас есть идеи, тогда plz ответьте – user3436439

ответ

1
SWRevealViewController *navigationController = (SWRevealViewController *)self.window.rootViewController; 
UINavigationController *nav = (UINavigationController *)navigationController; 

изменить ---------

UINavigationController *nav = (UINavigationController *)navigationController.frontViewController; 



UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 
PushNotificationsVC *controller = (PushNotificationsVC*)[mainStoryboard instantiateViewControllerWithIdentifier: @"PushNotificationsVC"]; 
[nav pushViewController:controller animated:YES]; 
+1

NavigationViewController * frontNavigationController = [NavigationViewController alloc] initWithRootViewController: frontVC]; NavigationViewController * rearNavigationController = [[NavigationViewController alloc] initWithRootViewController: rearVC]; SWRevealViewController * mainRevealController = [[SWRevealViewController alloc] initWithRearViewController: rearNavigationController frontViewController: frontNavigationController]; Я нашел решение Спасибо всем за прилагаемые усилия. Я не могу никого проголосовать. – user3436439

0

В качестве user34336439 упоминается с некоторыми дефектами слова, правильно ответ

FrontViewController *frontViewController = [[LiveScoreViewController alloc] init]; 
    RearViewController *rearViewController = [[RearViewController alloc] init]; 

    UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController]; 
    UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController]; 
    SWRevealViewController *mainRevealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController]; 

    self.window.rootViewController = mainRevealController; 
12

Для тех, кто следит за этим http://www.appcoda.com/ios-programming-sidebar-navigation-menu/ с помощью раскадровки.

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; 

Надеется, что это поможет кто-то другое ...

+0

Большое спасибо. Это сработало – Sakthimuthiah

+0

Удивительное решение спасибо :) –

+0

Это работает для меня, но скрывает мою заднюю кнопку, так как Im переходит к диспетчеру детского меню. –

3

Те, кто ищет быстрый ответ:

var storyboard = UIStoryboard(name: "Main", bundle: nil) 

    var destinationController = storyboard.instantiateViewControllerWithIdentifier("DestinationController") as? DestinationController 

    var frontNavigationController = UINavigationController(rootViewController: destinationController!) 

    var rearViewController = storyboard.instantiateViewControllerWithIdentifier("MenuController") as? MenuController 

    var mainRevealController = SWRevealViewController() 

    mainRevealController.rearViewController = rearViewController 
    mainRevealController.frontViewController = frontNavigationController 
    self.window!.rootViewController = mainRevealController 
    self.window?.makeKeyAndVisible() 
Смежные вопросы