iPad - 当有多个时,最顶层的模态视图控制器不会关闭

发布于 2024-09-28 15:31:35 字数 755 浏览 2 评论 0原文

我正在开发双 iPad/iPhone 应用程序。

我遇到的问题仅发生在 iPad 上:

  • 根视图控制器在 iPad 上是 UISplitViewController,在 iPhone 上是 UITabBarController
  • 模态 UIViewController 可以出现在根控制器上 模态
  • UIViewController 可以出现在之前的模态控制器上
  • 在 iPad 上,模态控制器正在使用 UIModalPresentationStyle.PageSheet

一切正常,除了从 iPad 中关闭最顶层的模态控制器 - 该方法被调用,但模态视图控制器不会关闭。我通过从前一个模态控制器调用 DismissModalViewControllerAnimated 来关闭。

有什么想法为什么这不能在 iPad 上运行吗?

在所有情况下,我都会从父控制器调用 PresentModalViewController 和 DismissModalViewControllerAnimated 来运行其子模态控制器。

我正在使用 MonoTouch(您可以通过我的方法大小写来判断),但这可能无关紧要。我也可以在 Obj-C 中得到答案。

更新,以下内容可能会使它应该做什么更清楚:

  • Root =>模态A =>模态 B
  • 关闭模态 B 应该返回 到模态 A
  • 关闭模态 A 应该返回 至根

I'm working on a dual-iPad/iPhone application.

I'm having a problem that is occurring on the iPad only:

  • Root view controller is a UISplitViewController on iPad, UITabBarController on iPhone
  • A modal UIViewController can appear over the root controller
  • A modal UIViewController can appear over the previous modal controller
  • On iPad, modal controllers are using UIModalPresentationStyle.PageSheet

Everything works, except dismissing the topmost modal controller from the iPad--the method is called, but the modal view controller doesn't dismiss. I dismiss by calling DismissModalViewControllerAnimated from the previous modal controller.

Any ideas why this wouldn't be working on the iPad?

In all cases, I call PresentModalViewController and DismissModalViewControllerAnimated from the parent controller to work its child modal controller.

I'm using MonoTouch (you can tell by my casing of methods), but that is probably irrelevant. I can take answers in Obj-C as well.

UPDATE, following might make what it should do more clear:

  • Root => Modal A => Modal B
  • Dismissing Modal B should just return
    to Modal A
  • Dismissing Modal A should just return
    to Root

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抹茶夏天i‖ 2024-10-05 15:31:35

你确定你否认的是正确的观点吗?在模态视图中,假设您想通过单击按钮来关闭视图。在该按钮的方法中,您想要调用 DismissModalViewControllerAnimated 方法。只需说

[self dismissModalViewControllerAnimated:YES];
  • 完成后从根呈现模式窗口
  • ,从模式视图的控制器中关闭视图。

如果不了解您如何尝试呈现和关闭控制器,则很难真正诊断问题,但这应该可行。一旦显示新视图,您不需要从父控制器执行任何操作...

Are you sure you are dismissing the right view? Inside the modal view, lets say that you want to dismiss the view with a button click. In that button's method, you want to call the DismissModalViewControllerAnimated method. Just say

[self dismissModalViewControllerAnimated:YES];
  • Present the modal window from the root
  • when finished, dismiss the view from the modal view's controller.

It's hard to really diagnose the problem without seeing how you are trying to present and dismiss the controller, but that should work. You shouldn't need to do anything from the parent controller once the new view is displayed...

開玄 2024-10-05 15:31:35

找到了解决方法。必须满足所有这些条件才能修复它:

  1. 第一个模态具有默认的 ModalPresentationStyle
  2. 第二个模态具有 UIModalPresentationStyle.PageSheet
  3. 我的第二个模态显示在第一个模态的 ViewDidAppear 中。由于某种原因,我需要从 BeginInvokeOnMainThread 调用 PresentModalViewController。 (MonoTouch 中的一句台词)这是我从 Windows 开发和消息泵中学到的一个技巧。我见过 iPhone 开发人员使用计时器做了类似的解决方法——这要好得多。

如果我们在通过应用程序商店获取此内容时遇到问题,我会回复。但就目前而言,这对我们来说是一个很好的解决方案。

Found a workaround. All of these conditions had to be met to fix it:

  1. First modal has default ModalPresentationStyle
  2. Second modal has UIModalPresentationStyle.PageSheet
  3. My second modal is displayed in the ViewDidAppear of the first. For some reason, I needed to call PresentModalViewController from BeginInvokeOnMainThread. (A one-liner in MonoTouch) This is a trick I learned from Windows development and message pumps. I have seen iPhone devs do similar workarounds with timers--this is much better.

I will post-back if we have trouble getting this through the app store. But for now, it is a good solution for us.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文