views:

77

answers:

2

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
+1  A: 

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

Geoff Baum
I was calling from the parent controller, but I tried calling this from the modal controller as you suggest and got the same result. There doesn't appear to be a problem until I get the second modal view on top. And for some reason only the iPad...
Jonathan.Peppers
Why exactly do you need that second modal view controller? I am not sure that will fly on in the app store. Why not just push another view on the view in the modal controller?
Geoff Baum
The first modal is a login screen. The second modal is a "first-run" screen where you enter your server's url that should only appear once. To go into detail on why, I would have to disclose more about out app. I'll work on reproducing it in a sample project. *Also:* I don't think using a UINavigationController on the login modal would work either, as the user shouldn't be able to back out and we don't want a nav bar.
Jonathan.Peppers
As a side note; you can hide the nav bar from a UINavigationController using navigationController.NavigationBarHidden = true;
Luke
Yeah what Luke said should work. You can just hide it, but still have it there. To be honest, that might be the most efficient way to go.
Geoff Baum
If I can't find another way, I'll have to use the UINavigationController. I will post my results.
Jonathan.Peppers
A: 

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.

Jonathan.Peppers