【问题标题】:NSNotification will not dismiss modal viewNSNotification 不会关闭模态视图
【发布时间】:2011-07-07 15:09:47
【问题描述】:

任务: 我有一个导航控制器,它推送一个模态视图,称为登录。这个登录视图有一个按钮可以推动另一个模态视图,称为注册。如果用户注册了注册模式并且登录模式应该关闭。我在登录视图中创建了一个 nsnotification,它等待来自注册提交操作的帖子。

问题 登录会收到通知,但不会关闭登录视图。我知道该方法运行,因为 NSLog 触发。

登录 viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismiss) name@"SignedUp" object nil];

登录关闭

NSLog(@"Dismiss"); // this fires
[self dismissModalViewControllerAnimated: YES];

注册方式(子控制器)

[self dismissModalViewControllerAnimated: YES];
[[NSNotificationCenter defaultCenter] postNotificationName:@"SignedUp" object:[self parentViewController]];

在注册方法中调用dismiss后我也试过这个

[self.parentViewController dismissModalViewControllerAnimated:YES];

编辑我不会推动这些控制器。我正在使用presentModalViewController

【问题讨论】:

  • 你有解决办法吗?

标签: iphone modalviewcontroller nsnotifications nsnotificationcenter


【解决方案1】:

如果你打算解散整个堆栈,为什么要一次解散它们?这可能不是通知的问题。您可以使用

弹出整个堆栈
[[[self parentViewController] parentViewController] dismissModalViewControllerAnimated:YES];

然后,如果您想再次显示它,只需再次将其设为presentModalViewController

我相信你可以通过https://stackoverflow.com/search?q=Dismiss+multiple+modal+controllers得到很多意见

【讨论】:

  • 这基本上是解决方案。我不得不将dismiss方法移动到所呈现模式的最根视图并添加了代码 [self.navigationControllerdismissModalViewControllerAnimated:YES];
【解决方案2】:

您如何展示您的模态视图?我问的原因是您说“推送模态视图的导航控制器”。

如果您使用的是pushViewController:animated:,那么它不是模态视图,您需要使用popViewControllerAnimated: 使其再次消失。

【讨论】:

  • 糟糕。我正在使用一些令人困惑的措辞。我正在使用 presentModalViewController
  • 在那种情况下,完全忽略我的回答!我只能假设因为您有嵌套的模式视图控制器,所以它会变得混乱,但您的代码应该可以工作。我会考虑的。 . .
猜你喜欢
  • 1970-01-01
  • 2021-05-04
  • 1970-01-01
  • 2011-09-27
  • 2011-12-26
  • 1970-01-01
  • 2014-10-24
  • 2011-04-05
  • 1970-01-01
相关资源
最近更新 更多