views:

535

answers:

1

I've noticed that there are two different ways to load nib files: 1) via the UIView's initWithNibName:bundle: method and 2) NSBundle's loadNibNamed:owner:options: method. Can someone explain the differences between these two and when it is more appropriate to use one over the other and in what circumstances?

For instance, if I'm loading a custom table section header view from a nib file in the tableView:viewForHeaderInSection: method, which one would I use?

Or, if I were loading a custom table view cell from a nib file, which one would I use?

+6  A: 

NSBundle’s methods are the generic API to use for unarchiving NIBs. They do the actual work (together with NSNib).

UIViewController’s initWithNibName:bundle: on the other hand is a way to initialize a view controller which (might) load its view from a nib. The method does not itself load the nib but just takes note of the name. The controller loads the nib lazily when the view is requested.

I’m not aware of any nib loading in UIView.

Nikolai Ruhe