获取本地通知时重定向到特定视图控制器

时间:2014-05-09 10:42:42

标签: ios objective-c uilocalnotification

我正在尝试实现本地通知及其工作正常但我的问题是当我的应用程序处于前台时我从服务器获取它会提醒我但是当我点击该警报并尝试重定向我的家在app-delegate文件中使用这个简单的代码查看控制器

- (void)didTapOnNotificationView:(CMNavBarNotificationView *)notificationView
{
    UIStoryboard *storyboard = [[self.window rootViewController] storyboard];
    HomeViewController *obj_home=[storyboard instantiateViewControllerWithIdentifier:@"Home"];
    UINavigationController* navigationViewController_test=[[UINavigationController alloc]initWithRootViewController:[storyboard instantiateViewControllerWithIdentifier:@"Home"]];

    [navigationViewController_test pushViewController:obj_home animated:YES];
}

使用此代码,它只会显示黑屏,任何人都可以告诉我在哪里犯了错误?和本地通知提醒我是使用第三方工具(CMNavBarNotificationView)并使用其委托方法(didTapOnNotificationView

1 个答案:

答案 0 :(得分:0)

您需要将navigationcontroller与当前位于导航堆栈中的viewcontroller链接起来。在下面的代码中我使用rootviewcontroller来呈现/推送HomeviewController,你可以用你想要的任何控制器替换它。

 - (void)didTapOnNotificationView:(CMNavBarNotificationView *)notificationView
    {
        UIStoryboard *storyboard = [[self.window rootViewController] storyboard];
        HomeViewController *obj_home=[storyboard instantiateViewControllerWithIdentifier:@"Home"];



      // either present the navigation controller as a modal 


        UINavigationController* navigationViewController_test=[[UINavigationController alloc]initWithRootViewController:obj_home];

        [self.window.rootViewController presentViewController:navigationViewController_test animated:YES completion:^{}];

     // OR push the home view. Here my rootViewController is a navigation controller, so I am pushing the home view directly from it. You can push it from any of the controller that is in the current navigation controller stack.

        [(UINavigationController *)self.window.rootViewController pushViewController:obj_home animated:YES];

    }

希望这有帮助。