Help. About organize view hierarchy in an app.

Discussion in 'iOS Programming' started by cthesky, Nov 2, 2012.

  1. cthesky macrumors member

    Joined:
    Aug 21, 2011
    #1
    Hi all,

    I really need some help and suggestions about organize the view hierarchy in my education app.

    In my app, it consists some view controllers as below:

    1. Menu View Controller - consists level buttons example: 'Level 1', 'Level 2'.

    2. Level View Controller - show the questions for each level.
    For example: When user click 'Level 1' button in Menu View Controller, this level view controller will show a view and display a number of questions let user answer.

    3. Result View Controller - show the result once user finish answer the questions.

    In this result view controller, it consists
    (a) 'Play Again' button - Once click it, will switch back to Level View Controller so user can play again.
    (b) 'Back to Menu' button - Once press it, it will switch back to menu view controller.
    (c) 'Play Next Level' button - When click it, it will switch to Level View Controller which will show different set of questions.

    I am not sure how to organize these view controller in a better way since it always need switch between the existing view controllers. Before this I am adding a view controller as a subview of another view controller to achieve 'switch view' purpose but it seems not a good practice. Am I need use navigation controller?

    Currently I am reading the view controller programming guide. But really hope someone can share their idea, suggestion and experience.

    Any comments are welcome. Thanks a lot. :)
     
  2. Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #2
    Yes, UINavigationController is probably what you want to use here, if you want standard iPhone-style sliding transitions between your menu and each level.

    You should also look into Storyboards. They're a good way to set up this sort of navigation without much coding:

    http://mobile.tutsplus.com/tutorials/iphone/ios-5-sdk-storyboards/
     
  3. cthesky thread starter macrumors member

    Joined:
    Aug 21, 2011
    #3
    Thanks for your reply. :)

    If use UINavigationController I may need hide the navigation bar in Menu and Result View Controller and display most of the buttons example level buttons in UIButton form instead of the navigation bar button. Am I right?

    Yes, storyboard is quite helpful but I heard it may not run in previous version IOS device. Am I right?
     
  4. Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #4
    Yeah, if you don't want a navigation bar, you can do it that way.

    It works in iOS 5.0 and up. Probably 98%+ of active iOS users are using iOS 5 and up already, so I would not worry about this.
     
  5. cthesky thread starter macrumors member

    Joined:
    Aug 21, 2011
    #5
    I see. Thanks for your help.

    But I have some questions regarding the navigation controller.

    1. If use navigation controller, how to pop out more than one view controller ? Let's say I need go 2 steps back. For example, in my app I know how to switch from result view controller back to level view controller but not sure how to switch from result view controller back to menu view controller.

    2. If I need include navigation bar in some of the view controllers only, so can I just hide the navigation bar when I don't want it and show it again if I need it to be seen ? Am I correct?

    Thanks. :)
     
  6. Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #6
    I think it's possible to call popViewController twice if you want to go up two levels in the stack.

    But the better way is to use:

    popToViewController:animated: to go to a specific ViewController on the stack,
    or popToRootViewControllerAnimated: to go all the way to the root viewController.

    Sure. Calling setNavigationBarHidden:YES animated:YES in the viewWillAppear (and, perhaps, the opposite in viewWillDisappear) of the appropriate viewController should do the right thing.
     
  7. cthesky thread starter macrumors member

    Joined:
    Aug 21, 2011
    #7
    Hi, Thanks ! You really help me a lot. :)
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Be sure you've read the View Controller Programming Guide (something I suggested previously in another thread of yours).
     
  9. cthesky thread starter macrumors member

    Joined:
    Aug 21, 2011
    #9
    Yes, I know it and is reading. Thanks. :)
     

Share This Page