Question about ViewController instantiation when starting an app

Discussion in 'iOS Programming' started by vcanic, Feb 4, 2010.

  1. vcanic macrumors newbie

    Feb 4, 2010

    The last couple of weeks I have been reading a lot of tutorials on how to design your application (regarding ViewControllers0 when starting to code on the iPhone.

    Two different examples examples:

    - Within your appDelegate define a RootViewController/MainViewController that instantiates all your other ViewControllers. All these ViewControllers are added to the window (MainWindow.xib). So this makes appDelegate and the MainWindow 'all-knowing' if it comes to the ViewControllers and their associated Views.
    I would assume that this is really memory consuming.

    - Instantiate your ViewControllers and their associated Views as you go. So your appDelegate and window (MainWindow) will only know 1 ViewController and that ViewController knows it's child and so on. For example:
    LoginViewController --> CustomerViewController --> CreatedCustomerViewController etc.
    I would assume that this is much more efficient.

    My question is: What is the best way on going to programming and designing your application when choosing one of those examples? Or are there other and better ways?

    Some tips would be much appreciated. Thanks in advance.
  2. csnplt macrumors 6502


    Aug 29, 2008
    Chicago Area
    I usually just use the View app template in XCode. If I need a tab bar controller or navigation controller, I'll declare that in the App Delegate rather than another view controller, and I'll just push more views onto the stack when I need to (with nav controller).
  3. vcanic thread starter macrumors newbie

    Feb 4, 2010
    Does this mean that you only use the "nav controller" for pushing views onto the stack and nothing else?

    Also, in this case all your controllers are instantiated within the App Delegate?

Share This Page