presenting modal views in a popover

穿精又带淫゛_ 提交于 2020-01-04 03:36:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!