从本地通知的警报视图导航到视图控制器

时间:2016-08-26 15:06:03

标签: ios objective-c uialertview uilocalnotification

在点击通过接收本地通知呈现的警报视图按钮时,我必须移动到已经嵌入在导航控制器中的视图控制器。请提前建议如何执行此操作

- (void)application:(UIApplication *)application didReceiveLocalNotification:(nonnull UILocalNotification *)notification
{
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder"
                                                        message:notification.alertBody
                                                       delegate:self cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Read more",nil];
        _SelectedPOI=[notification.userInfo valueForKey:@"poiID"];
        alert.delegate=self;
        [alert show];
    }
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ 
   if (buttonIndex == 1)
    {
    // here i have to navigate to a view controller which is already embedded 
    in a navigation controller from another view controller
    }
}

1 个答案:

答案 0 :(得分:0)

UIAlertView已被删除。您应该使用UIAlertController。要呈现一个viewCOntroller或推送一个viewController你有很多选择。

一种方法是使用storyboardID来完成。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ 
   if (buttonIndex == 1)
    {
    // here i have to navigate to a view controller which is already embedded 
    in a navigation controller from another view controller

     OtherVC *vc =[self.storyboard instantiateViewControllerWithIdentifier:@"storyboard-id"];
     [self presentViewController:vc animated:YES completion:nil];
    }
}

确保故事板中的OtherVC为UINavigationController,而不是导航控制器中嵌入的VC。