Sal Aldana
Sal Aldana

Reputation: 1235

Present Modal View Controller from inside Popover View

So in my universal app I have a section where a person can look at an existing list of notes from our system (retrieved through a simple web service) and then also create a new note if they want. So for the iphone it's pretty simple layout, a TableViewController for displaying the list with a "Add" button on the NavigationBar that presents the modalview for adding the new item. On the iPad though, the same layout has a lot of wasted space so I opted to go with the popOver method to show the list in a popOver and then let them add from there. My problem is that when the user clicks on the Add button within the PopOver view, the modal view comes up full screen instead of just coming up within the popover view. Here's the code I have so far:

-(void) AddButtonPressed:(id)sender {

NewNoteVC *newNote = [[[NewNoteVC alloc] initWithNibName:@"NewNoteVC" bundle:nil] autorelease];
newNote.defaultClientID = defaultClientID;
UINavigationController *navCon = [[[UINavigationController alloc] initWithRootViewController:newNote] autorelease];
if ([isPopOver isEqualToString:@"YES"]) {
    [navCon setModalInPopover:YES];
    [self.navigationController setModalInPopover:YES];
    [self.navigationController presentModalViewController:navCon animated:YES];
}
else {
    [self.navigationController presentModalViewController:navCon animated:YES];
}

}

The "isPopOver" string is just a placeholder sent from the previous screen that called this TableView (I know I can switch this to a boolean for better performance I just put this together real quick to try it out). I know I messed up somewhere, I just don't know what setting I need to get this working correctly.

Upvotes: 9

Views: 8472

Answers (2)

rmaddy
rmaddy

Reputation: 318774

You need to define the view controller's modalPresentationStyle to be "current context".

navCon.modalPresentationStyle = UIModalPresentationCurrentContext;

This will result in modal view controller filling the popover like the popover's root controller.

Upvotes: 26

Martin Ullrich
Martin Ullrich

Reputation: 100543

Try using the presentViewController:animated:completion: instead of presentModalViewController:animated: and set self.navigationController.definesPresentationContext = YES

Upvotes: 2

Related Questions