开发者

iPad - topmost modal view controller won't dismiss when there are multiple

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


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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜