sengbsd
sengbsd

Reputation: 31

presenting modal views in a popover

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]; }

Upvotes: 3

Views: 12339

Answers (3)

cidered
cidered

Reputation: 3251

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.

Upvotes: 2

Robert Höglund
Robert Höglund

Reputation: 10070

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.

Upvotes: 19

ohho
ohho

Reputation: 51911

It's because you presentModalViewController to self. Try to add a UIBarButtonItem in your ViewController (self) and do:

[controller presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

where sender is the UIBarButtonItem

Upvotes: 0

Related Questions