将ViewControllers添加到堆栈并弹回需要时

时间:2016-08-26 06:39:11

标签: ios push-notification

我想在通知栏中单击通知时导航到特定的类,然后在该特定类中导航到如果我单击后退按钮我需要根据需要导航到上一个。

任何人都可以帮忙。

我已经将ViewController添加到Stack这样

  • (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIStoryboard * mainStoryboard = [UIStoryboard storyboardWithName:@" Main"捆绑:nil];

    SplashViewController * splashViewCon =(SplashViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" SplashId"];

    AgreeViewController * agreeViewCon =(AgreeViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" agreeView"];

    ViewController * loginViewCon =(ViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" loginView"];

    LanguageViewController * languageViewCon =(LanguageViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" languageView"];

    LandingScreenViewController * landingViewCon =(LandingScreenViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" landingScreenId"];

    HomeScreenViewController * homeViewCon =(HomeScreenViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" homeScreen"];

    OrderConfirmationViewController * orderconfirmViewCon =(OrderConfirmationViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" orderConfirmationVC"];

    ThankYouViewController * thankViewCon =(ThankYouViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" ThankyouId"];

    UploadQueueScreenViewController * uploadViewCon =(UploadQueueScreenViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" uploadQueue"];

    NewOrderViewController * newOrderViewCon =(NewOrderViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" neworderView"];

    MessageViewController * msgViewCon =(MessageViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" MessageInboxscreen"];

    MessageDetailsViewController * msgdetailsViewCon =(MessageDetailsViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" msgDetailsView"];

    NSArray * stack = [NSArray arrayWithObjects:splashViewCon,agreeViewCon,loginViewCon,languageViewCon,landingViewCon,homeViewCon,orderconfirmViewCon,thankViewCon,uploadViewCon,newOrderViewCon,msgViewCon,msgdetailsViewCon,nil]; navController.viewControllers = stack;

    UILocalNotification * notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

    if(通知) {     MessageDetailsViewController * msgdetailsViewCon =(MessageDetailsViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@" msgDetailsView"];     ;     self.window.rootViewController = msgdetailsViewCon; } }

所以,我想要回到特定的viewController

2 个答案:

答案 0 :(得分:2)

在堆栈中找到你的viewcontroller并弹出它。此代码可能会帮助您找到它。

for (YourViewController *controller in self.navigationController.viewControllers)
        {
            if ([controller isKindOfClass:[YourViewController class]])
            {
                [self.navigationController popViewController:controller animated:YES];
                break;
            }
        }

答案 1 :(得分:0)

据我所知,没有通用类avaialbe。尝试使用NSMutableArray,通过addObject添加并通过objectAtIndex和removeObjectAtIndex获取第一个/最后一个。

您可能想要实现自己的代码以将其用作堆栈。 干杯:)