UINavigationController stack

Discussion in 'iOS Development' started by acca2o, Oct 27, 2009.

  1. acca2o

    acca2o New Member

    Joined:
    Sep 26, 2009
    Messages:
    51
    Likes Received:
    0
    Device:
    2G iPod touch
    I'm building a general template for my applications.
    A window, a UITabBarController, some custom ViewControllers and some UINavigationController.
    Every is working but the NavigationController.
    When I touch the tab to open a NavigationController, it show the last ViewController and the back button.
    So I think I'm using in the wrong way the UINavigationController.

    First I create it by
    UINavigationController* nc = [[UINavigationController alloc] init];

    Then create a NSArray* navigationStack with the custom ViewControllers (from the first - root- to the last) and push it in NavigationController by:
    [nc setViewControllers:navigationStack animated:YES];

    Have I to push just the root custom ViewController and then push the others later depending on the user actions?
    Or can I push all the custom ViewControllers at the start?
    In the first case is the back button responsable for poping the last custom ViewController?

    Thanks
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Override the tab bar delegate methods to get the click on the tab. Then use [yourNavigationController popToRootViewControllerAnimated:NO]; Or whatever the method is.

    Although, the much better way to deal with a UINavigationController is to create it using -initWithRootviewController: It is horrible memory management to have all those view controllers pushed onto the stack before they need to be. Not to mention your application will slow down tremendously at start up as all those view controllers must be created.

    When something happens to cause the navigation controller to push a new view controller, you should create the new view controller then. As soon as it's created, push it. As soon as it's pushed, release it. As in, three lines of code.
  3. acca2o

    acca2o New Member

    Joined:
    Sep 26, 2009
    Messages:
    51
    Likes Received:
    0
    Device:
    2G iPod touch
    OK, I supposed that was the rigth way (the second one).

    I create all the controllers inside the UIApplication subclass instance.
    Is that object the best place where to manage the events coming/going from/to the view/navigation controllers (to build a inter-controller communication)?
    I'm a beginner with ipod dev, I come from a lot of action scrips (AS3) developing for flash applications and, there, the events move up from from child to parent. so the place where I build cross-objects-messaging is the first common parent of the two objects.
    Is nearly the same with objc?

    Is it right to suppose the back button in UINavigationController cancels the last viewcontroller from the stack? In that case is the memory freed (if the viewcontroller has been released once inserted in the stack)?

Share This Page