Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

pushViewController versus presentModalViewController

Oliver DrobnikOliver Drobnik Vienna, AustriaPosts: 538New Users, Registered Users @ @ @
edited September 2008 in iOS SDK Development
Hi,

can anyone explain what the difference is between PushViewController and presentModalViewController?

iside a navigation view controller:


AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];


[self pushViewController:anotherViewController animated:YES];

versus

[self presentModalViewController:anotherViewController animated:YES];


gives a different result. With the first I see the Navigation bar updated according to what I set in the XIB. With the second the window slides in from below, but is missing a navigation bar.

my anotherView XIB consists of the following:

File's Owner
First Responder
View
Navigation Bar
Navigation Item
Bar Button


I am looking at the SQL Books sample and there the same XIB is used. For Editing the view slides in from the right. For adding it slides in from below. I don't see why the modal version would not show the navigation bar ...
Post edited by Oliver Drobnik on
Buy my book "Barcodes with iOS 7": http://bitly.com/barcodes_iOS

Get 50% until March 9th with promo code "mldrobnik"
· ·

Replies

  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    edited September 2008
    Um, because it's modal? The whole idea behind a modal view is that it prevents you from doing anything except whatever it is that it wants you to do. It puts you in a 'mode'. It will usually have an ok button or cancel and ok buttons. You must do something specific to exit the modal state.

    The nav bar is more flexible and doesn't require you to do a specific action before exiting to another view.

    The modal view covers up the nav bar to create the mode.

    Choose one or the other based on your need.
    · ·
  • scottiphonescottiphone Posts: 802Registered Users
    edited September 2008
    You can add a navbar in Interface builder with cancel and done for modal views.
    · ·
  • Oliver DrobnikOliver Drobnik Vienna, AustriaPosts: 538New Users, Registered Users @ @ @
    edited September 2008
    Well I have a nav bar in the xib but it does not show in modal, that is what confuses me.
    Buy my book "Barcodes with iOS 7": http://bitly.com/barcodes_iOS

    Get 50% until March 9th with promo code "mldrobnik"
    · ·
  • scottiphonescottiphone Posts: 802Registered Users
    edited September 2008
    Just drag the navbar over your view. Add barbutton items accordingly. If you're not seeing it then it's not on a view or is behind the view. Check the outline view for order of display.
    · ·
  • Oliver DrobnikOliver Drobnik Vienna, AustriaPosts: 538New Users, Registered Users @ @ @
    edited September 2008
    Well just reordering the pieces in the XIB did not change anything. Then I put in some code that I had seen before, with strange results:

    AnotherViewController *controller = [self anotherViewController];
    controller.editedWish = nil;
    if (addNavigationController == nil) {
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
    self.addNavigationController = navController;
    [navController release];
    }

    [self.navigationController presentModalViewController:controller animated:YES];

    With this I do see a Navbar, but no buttons. Well in the sample the anotherViewController seems to add the buttons programmatically in the ViewDidLoad function. But why does it not pick up the buttons I created in my XIB?

    So is it true that I need to initWithRootViewController if I want presentModal and I don't need it with the pushViewController? Why?
    Buy my book "Barcodes with iOS 7": http://bitly.com/barcodes_iOS

    Get 50% until March 9th with promo code "mldrobnik"
    · ·
  • scottiphonescottiphone Posts: 802Registered Users
    edited September 2008
    You're making this much more difficult than it needs to be.
    Create 2 view controllers.
    Within a method for your master view controller load the other and just present it from the master view controller.
    	MyOtherController *otherVC = [[MyOtherController alloc]  initNibInMyOwnWay  ];
    	
    	[self presentModalViewController: otherVC animated:YES];
    	[otherVC release];
    
    · ·
  • Oliver DrobnikOliver Drobnik Vienna, AustriaPosts: 538New Users, Registered Users @ @ @
    edited September 2008
    and how should the two xib files look if I want a nav bar with two buttons to show up?

    Or can I use just one xib?
    Buy my book "Barcodes with iOS 7": http://bitly.com/barcodes_iOS

    Get 50% until March 9th with promo code "mldrobnik"
    · ·
Sign In or Register to comment.