Is This The Best Way To Add NavigationController as Subview

Discussion in 'iOS Programming' started by zachsilvey, Dec 18, 2010.

  1. zachsilvey macrumors 6502

    Joined:
    Feb 5, 2008
    Location:
    Battle Ground
    #1
    I am currently using this
    Code:
    [[[UIApplication sharedApplication] keyWindow] addSubview:navView.view];
    to add the navigation controller view to the window from inside a UIViewController.

    Correct me if I'm wrong but UINavigationController expects to be added to a UIWindow not as a subview of a UIView?

    The main issue I'm hitting is that when I try to animate the view switching it doesn't work.
     
  2. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #2
    Yes and no. For example, you can have it as a subview in tab bars so in short, it isn't necessary to have them as a first thing on top of the main window.

    On the other hand, it is a good idea to create a nav controller as soon as possible. I wasted some time trying to make navigation controllers behave in the unusual ways and at the end I think it is the best practice to create it at start. If you don't need it there, just make it hidden and later when you do need it make it visible.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    What makes you think that simply adding a subview will have animation?
     
  4. zachsilvey thread starter macrumors 6502

    Joined:
    Feb 5, 2008
    Location:
    Battle Ground
    #4
    I don't, I used the standard block of
    Code:
    [UIView beginAnimations:@"blah" context:nil];
    
    ...
    
    [UIView commitAnimations];
    Around that line like I usually do when animating the adding of a subview.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    And what property are you animating? You know, providing a before and after value. You might want to include the whole code block.

    And when you say "it doesn't work", what do you mean exactly? The more specific, the better.
     

Share This Page