Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
Hey,

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

If you use Interface Builder, it is recommended that you set up the views for your view controllers in separate nib files—that is, you create a nib file for each application view. In this case, you set the File’s Owner to your view controller subclass and connect the File’s Owner view outlet to the root view in the nib file. You can then create the view controller programmatically using the initWithNibName:bundle: method or by setting the view controller’s nib file name in Interface Builder. When you set the nib file name, an instance of your view controller class is created and initialized with the contents of the specified nib file.

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
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Select the file owner and set its class to your custom class. Post again if this doesn't make sense.
 

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
Select the file owner and set its class to your custom class. Post again if this doesn't make sense.

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.
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
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 ;).
 

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
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 ;).

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.