views:

703

answers:

2

Hi,

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

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

ohho
Well 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.
sengbsd
sorry that I misunderstand your question. I have no experience of loading a modal view _inside_ a popover...
ohho
A: 

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.

Robert Höglund