Domanda

This seems like a really silly question, but when I create a nib file and drop a UIViewController in it, I'm not able to add anything to it. But if I do a UIView it's fine. If I create a UIViewController and select "use nib" it creates a nib with a UIView in it, not a UIViewController.

This is different from storyboards that allow you to have UIViewControllers and UIViews be separate. Is this not the case with nibs?

È stato utile?

Soluzione

It's possible to have any object in a nib. Literally, any object that can exist in your app can be in a nib.

However when you're doing nib-based (as opposed to storyboard-based) design, you don't usually put the view controller in the nib. The normal approach is to create the view controller in code, usually with the initWithNibName:bundle: method. The nib will be configured with the view controller as "file's owner", which is a reference to an external object not contained in the nib. The nib contains the view that the view controller uses, connected to the VC's view outlet.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top