I'm missing something with a common Cocoa design pattern.

Discussion in 'iOS Programming' started by SERAPHRowen, Sep 17, 2010.

  1. SERAPHRowen macrumors newbie

    Joined:
    Sep 15, 2010
    #1
    So, I've been writing an app based loosely on this tutorial:
    http://developer.apple.com/library/...iPhoneCoreData01/Articles/01_StartingOut.html

    My basic problem is, the AppDelegate creates the window and the navigation controller, but the add button for the navigation bar is created in the root view controller. I need the add button to push a view controller with the navigation bar. However, the view controller and the navigation bar are created and stored in the AppDelegate. The view controller I want is a xib I've setup in interface builder, and the delegate has an output link that references it. I tried setting the delegate of my root view controller to be the app delegate, but it doesn't appear to have a delegate member variable.

    I feel like I'm missing something core to this language, since the example provided by apple seems to be oxymoronic ( but almost certainly isn't.) Feel free to give a "read up on X noob" response, I realize this is almost certainly some core misunderstanding I have about working in this environment. I'm just not sure where to start looking.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You can access the app delegate from anywhere very easily via the shared UIApplication object.
     
  3. SERAPHRowen thread starter macrumors newbie

    Joined:
    Sep 15, 2010
    #3
    Thank you! Reading up on that now.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Normally, if you are within a viewController that's already on the nav-stack, you can simply call:
    Code:
    [self.navigationController pushViewController:[I]newViewController[/I] animated:YES];
    
     
  5. SERAPHRowen thread starter macrumors newbie

    Joined:
    Sep 15, 2010
    #5
    Yeah, the problem I was having with that is that the view controller is still referenced in the delegate.

    Reading up on UIApplication resolved my misunderstanding, and implementing accordingly resolved my issue. Thanks guys.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Also, just to be clear, a view controller and a xib are two different, though sometimes related, things. So, saying a view controller is a xib is not really stating it correctly.
     

Share This Page