Ios 无法从UIAbbarController中关闭UIViewController

Ios 无法从UIAbbarController中关闭UIViewController,ios,uiviewcontroller,uitabbarcontroller,Ios,Uiviewcontroller,Uitabbarcontroller,我有一个iOS应用程序,它在根目录下有一个UITabBarController(有三个选项卡) 在ViewDidDisplay中的第一个选项卡中:如果用户尚未注册,我将提供以下内容: UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; RegisterViewController *registerViewController = [mainStoryboar

我有一个iOS应用程序,它在根目录下有一个UITabBarController(有三个选项卡)

在ViewDidDisplay中的第一个选项卡中:如果用户尚未注册,我将提供以下内容:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
RegisterViewController *registerViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"RegisterView"];
[registerViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:registerViewController animated:NO completion:nil];
当用户点击RegisterViewController中的“Register”(注册)按钮时,收到HTTP响应后,它会显示QuestionnaReviewController

当点击QuestionnaReviewController中的“Submit”(提交)按钮时,我可以通过以下方式消除此问题:

[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
然后,我发布了RegisterViewController正在侦听的通知:

[[NSNotificationCenter defaultCenter] postNotificationName:UserHasCompletedQuestionnaireNotification object:nil];
现在,我的问题就出在这里——当RegisterViewController听到通知时,我尝试取消它,但无法

我尝试过各种各样的否定它的含义,例如:

[[self tabBarController] dismissViewControllerAnimated:YES completion:nil];
什么都不做,而且:

[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
这会产生以下错误:

attempt to dismiss modal view controller whose view does not currently appear. self = <RegisterViewController: 0x8525ea0> modalViewController = <UINavigationController: 0x74545e0>
attempt to dismiss modal view controller whose view does not currently appear. self = <UITabBarController: 0x8320060> modalViewController = <RegisterViewController: 0x8525ea0>
尝试关闭视图当前未出现的模态视图控制器。self=modalViewController=
尝试关闭视图当前未出现的模态视图控制器。self=modalViewController=
希望有人能告诉我我做错了什么愚蠢的事

谢谢, 尼克

试试看:

[self dismissViewControllerAnimated:YES completion:nil];
而不是:

[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
如果要同时关闭两个控制器,可以消除通知,然后执行此操作(来自QuestionnaReviewController):


如果我正确理解您的结构,self.presentingViewController.presentingViewController应该是显示RegisterViewController的第一个选项卡中的控制器。取消它也会取消它呈现的任何内容。

[自我取消查看控制器:是完成:否];用于关闭接收者显示的视图控制器,因此在本例中不起作用,因为RegisterViewController是我希望关闭的视图控制器。我已经尝试过,但不幸的是,它没有任何作用。如果您记录self.presentingViewController.presentingViewController,它给了你什么?self.presentingViewController=UITabBarController,self.presentingViewController.presentingViewController=null我诚挚的道歉rdelmar,我误读了你最初的答案。我已经给presentingViewController.presentingViewController打了电话,问题中有presentingViewController,它可以工作-非常感谢。但是我仍然不明白为什么我的原始设计不能工作。
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];