1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Setting the view controller’s nib file name in Interface Builder

Discussion in 'Mac Programming' started by RossOliver, Jun 15, 2008.

  1. macrumors regular

    #1
    Hey,

    Reading through the apple documentation, I came across this paragraph:

    How exactly do I set the view controller's nib file name in IB? Also, how would I then go on to create an instance of my view controller so it loads the nib and so I can then add it as a sub view etc...

    Full document here: http://developer.apple.com/iphone/l...1.html#//apple_ref/doc/uid/TP40007457-CH5-SW1

    Cheers
     
  2. macrumors G4

    Eraserhead

    #2
    Select the file owner and set its class to your custom class. Post again if this doesn't make sense.
     
  3. macrumors regular

    #3
    Ah, I had done that - I thought there was more to it :confused:...

    Another question you (or anyone else) may be able to help with. The MainWindow.xib that is provided - should that be left blank and should I create my main view in another nib, say MainView.xib or should I just create the view in MainWindow.xib?

    I ask because it doesn't make sense to me how the MainWindow.xib view would be correctly handled - surely it needs a view controller, but I wouldn't be able to make the view controller it's file's owner. Would this mean I would have to load the view using initWithNib? (that method may not be accurate)

    Thanks again.
     
  4. macrumors G4

    Eraserhead

    #4
    You should just stick the main view in the first .xib

    With regards to having lots of multiple files there used to be two reasons for having multiple .nib files for everything.

    1) Its easier to localise if you are using version control software. But with the new .xib format that is no longer a big issue. I suppose its a slight issue still as the translators don't know what has changed as clearly, but it shouldn't matter too much.

    2) There might be slightly worse performance, to put this in perspective on the Mac I have nibs with 20 windows and that part of loading takes around 1/1000th of a second. On the iPhone this may be more of an issue, but you should be OK with having a small number of views in the same nib without issue, you'll have to performance check this yourself ;).
     
  5. macrumors regular

    #5
    OK, I think I understand now :)

    Last question (hopefully) - I have an interface consisting of a UIView, UITableView and a UIButton.

    The file's owner is set to a UIViewController which has an IBOutlet for the UIButton and UIView. It also has an IBAction method to handle the UIButton press.

    I have a UITableViewController for the UITableView datasource/delegate methods.

    What I want to do is refresh the UITableView when the UIButton is pressed, but what I can't work out is how to let the UIViewController know about the UITableViewController so it can refresh the UITableView. Do I just add the UITableView as an IBOutlet in the UIViewController and hook it up in IB?

    Cheers
     

Share This Page