presenting modal views in a popover
Solution 1
If you add
controller.modalPresentationStyle = UIModalPresentationCurrentContext;
before the call to presentModalViewController:animated your ModalVC should be displayed within the popover.
Another way to display something modally in a popover is to use the property modalInPopover.
Solution 2
Unfortunately, it seems you cannot to this and it violates the HIG. From Apple's View Controller Programming Guide
Note: You should always dismiss the visible popover before displaying another view controller modally. For specific guidelines on when and how to use popovers in your application, see “Popover (iPad Only)” in iOS Human Interface Guidelines.
sengbsd
Updated on June 16, 2022Comments
-
sengbsd about 2 years
Im trying to load a modal view from a view controller that is displayed in a popover. The modal view loads but the problem is that it transitions into the main view and not within the popover. Is it something Im missing? I thought simply initiating it from a vc within a popover would present the modal view within the same popover...
The code is nothing special as bellow:
- (IBAction)myButton{ ModalVC *controller = [[ModalVC alloc] initWithNibName:@"ModalVC" bundle:nil]; [self presentModalViewController:controller animated:YES]; [controller release]; }
-
sengbsd about 14 yearsWell I thought self was the viewcontroller that already is in the popover as thats where the code is. I already have a barbutton that has opened a viewcontroller in a popover. What I am trying to do is transition the viewcontroller in the popover to a new one using a modal transition.
-
ohho about 14 yearssorry that I misunderstand your question. I have no experience of loading a modal view inside a popover...
-
Ethan Allen about 13 yearsNeither of these worked for me to display a camera view inside of a popover.
-
Christopher Pickslay over 12 yearsSetting modalPresentationStyle to UIModalPresentationCurrentContext on the modal controller (not the presenting controller) does indeed work.
-
Greg Maletic over 12 yearsApple does this themselves in Messages app for iPad. When editing certain data about a contact (their special Ringtone, for example), they will bring up a modal view controller within the already-displayed popover. And, it makes sense for it to work this say. So, I'd argue this is the correct behavior, despite what the HIG says. (In fact, the UIModalPresentationStyle "UIModalPresentationCurrentContext" is designed for this explicit purpose, according to the Apple's docs.)
-
NetworkBurger over 11 yearsThose claiming it doesn't work: are you setting .modalPresentationStyle on your view controller, or the UINavigationController it's probably inside of? (You need to set on the nav controller)
-
titaniumdecoy over 11 yearsI would assume this quotation means that you should not present another view controller modally behind the current popover without closing it; I don't think it pertains to presenting a view controller modally within a popover.