Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 594
Sal Aldana Avatar asked Mar 14 '13 19:03

Sal Aldana


People also ask

Can a presented view controller also be a presenting view controller?

Yes a presented VC can present another VC.

How do you present a modal view controller programmatically?

Use presentViewController:animated:completion: instead.) The default modal presentation style is a card. This shows the previous view controller at the top and allows the user to swipe away the presented view controller. This is the same for both programmatically created and storyboard created controllers.

What is a UIViewController?

The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.


2 Answers

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.

like image 113
rmaddy Avatar answered Sep 21 '22 19:09

rmaddy


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

like image 31
Martin Ullrich Avatar answered Sep 18 '22 19:09

Martin Ullrich