Elye
Elye

Reputation: 60211

Why when create new UIView class, can't create a XIB together?

If I create a new UIViewController class, I could also checked the box to Also create XIB file.

However, why when I create UIView, the check box is disabled, and I have to manually create a XIB to link the two (XIB and the UIView) together?

enter image description here

Upvotes: 4

Views: 1481

Answers (1)

matt
matt

Reputation: 535536

If I create a new UIViewController class, I could also checked the box to Also create XIB file. However, why when I create UIView, the check box is disabled, and I have to manually create a XIB to link the two (XIB and the UIView) together? [Emphasis mine.]

Because the relationship between a view controller and a nib is totally different from the relationship between a view and a nib. UIView and nibs do not "go together" in any magic or important way, as do a UIViewController and its view nib.

  • With a view controller, if there is a nib with the same name as the view controller class, and if the File's Owner in that nib is typed as the class of the view controller, and if the view outlet of the File's Owner is pointed at the top-level UIView in the nib, the view controller can load its view automatically from the nib. That is a complicated arrangement, and it is doubtful that you would know how to configure it correctly (and it's a lot of work even if you do know how), so the template offers to configure it for you. This is a standard, important, automatic relationship.

  • But with a view and a nib there is no such standard automatic relationship, and there is no complexity. If you want a certain view in a certain nib to be of a certain UIView subclass, you just say so in its Identity inspector, and kaboom you're done. So just do that and move on.

Upvotes: 9

Related Questions