问题
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]; }
回答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.
回答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.
回答3:
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
来源:https://stackoverflow.com/questions/2823250/presenting-modal-views-in-a-popover