关闭视图控制器

时间:2017-05-12 05:24:39

标签: ios objective-c uinavigationcontroller

UIViewController中的storyboard未与UINavigationController相关联。当用户点击本地通知时会显示,现在我想在按下按钮时将其关闭并返回UINavigationController中的根视图控制器。

哪种方法最好?

4 个答案:

答案 0 :(得分:0)

您可以在提供的控制器上调用dismiss方法关闭它并返回到原来的位置。

<强>目标-C:

[self dismissViewControllerAnimated:YES completion:nil];

对于Navigation Controller,如果要在dismissViewController方法的完成块中使用根视图控制器:

[self.navigationController popToRootViewControllerAnimated:YES];

<强>夫特:

dismiss(animated: true, completion: nil)

答案 1 :(得分:0)

您可以点击按钮,

    UINavigationController *nav = (UINavigationController*)self.presentingViewController;

[self dismissViewControllerAnimated:YES completion:^{

    [nav popToRootViewControllerAnimated:YES];
}];

答案 2 :(得分:0)

在AppDelegate.m中调用方法: - didReceiveRemoteNotification 打开通知视图..

UIStoryboard *storyboard = self.window.rootViewController. storyboard; 
NotificationView *objNoti = [storyboard instantiateViewControllerWithIdentifier: @"Notificationview"]; 
[self.window.rootViewController presentViewController:objNoti animated:YES completion:nil];

然后按下工作通知后退按钮以关闭视图......

[self dismissViewControllerAnimated:YES completion:nil];

答案 3 :(得分:0)

首先出现如下:

UIStoryboard *storyboard = self.window.rootViewController.storyboard; UIViewController *newViewController = [storyboard instantiateViewControllerWithIdentifier:@"xyzVC"]; 

[self.window.rootViewController presentViewController:newViewController animated:YES completion:nil];

现在当您关闭newViewController 时,您将自动导航到根视图控制器