Multiple Views in a NIB; How to Access ?

Discussion in 'iOS Programming' started by Fontano, Oct 8, 2008.

  1. Fontano macrumors member

    Jun 27, 2008
    This may just be me having a bad day, but I am hitting a wall here.

    I have started a new empty project (I am trying out some theories before taking it back to the main development)

    I have two views in the .nib
    ViewA and ViewB

    In my ViewController I have two UIView declerations as IBOutlet

    @interface iDirecTVViewController : UIViewController {
    	UIView *viewA;
    	UIView *viewB;
    // Object Exposure
    @property (nonatomic, retain) IBOutlet UIView *viewA;
    @property (nonatomic, retain) IBOutlet UIView *viewB;
    Via Interface Builder, I am able to assign:
    NIBViewA -> view

    That would be the default startup view for the controller.
    Build/Run in simulator, everything fine.

    Then if I assign:
    NIBViewB -> viewB

    Upon the start of the Interface Builder, I get an unexpected error and can't run. Debugger isn't showing me much, unless I am just not seeing the issue.

    This happens as well if I assign NIBViewA ->viewA

    Any ideas on what is wrong?
    In a nutshell, I want to have multiple views in a NIB file, and assign them to object variables in the code so I can access them when different events occur.

    Like I said, could just be a bad day thing so please accept my apologizes if this is a simple trivial thing, simple searches didn't turn up any other posts.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    This should work. If you control-click on File's Owner or any other item in the xib window a little black window opens showing you the connections. Check this for all the views and the File's Owner to see if all your connections are correct.
  3. Fontano thread starter macrumors member

    Jun 27, 2008
    Yep, double checked there and in the Identity windows.
    All the views are pointing to their correct variables.

    I was able to snag this error message from the console:
    "*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x44e8b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key viewA.'
    Quick google searches, come up with that I am missing the definition in the header file, but it is there. I typically try to write my header files and link back to them, rather then draw the UI in IB and have it generate the matching header. Maybe I will try that next just to see if it does something different.
  4. Fontano thread starter macrumors member

    Jun 27, 2008
    Well, I managed to get it to work.

    Here is what I did.

    Everything in the .xib for the ViewController, and the ViewController files was fine.

    Where I had to make a change, was in the MainWindow.xib
    Even though my view for the NAVIGATION CONTROLLER was set to the proper .xib file, and it was loading the correct "view"

    It was pointing to the generic class UIViewController
    Once I changed it to the specific viewControllerTest class, all is fine now.

Share This Page