Does XIB always need a view controller?

If I use the interface in IB , do I always need a UIViewController base or can I just go to UIView ?

I am currently doing all my development in obj-c , which makes the work more busy.

If I need to use a UIViewController , one way or another, to disconnect a UIView from it, if that's all I want?

I just want to pull static layouts from XIB instead of XIB them to obj-c .

Any suggestions are welcome!

+4
source share
4 answers

UIViewController has this convenient initWithNib: bundle: method, which makes everything so simple, but there are also ways to get objects from xibs via:

 NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"WhateverItsNamed" owner:self options:nil]; 

(and the nib array here contains objects that correspond to certain objects stored in the XIB file).

+1
source

No, you do not need a UIViewController if it does not meet your needs.

After initializing UINib, use it:

 -instantiateWithOwner:options: 

to access the content. Create the root nib object as a UIView (or its subclass). If you plan to connect to File Owner, you will need to set File Owner in the appropriate context class.

+1
source

No, you do not need to bind the UIViewController with the XIB.

First, do not add a view controller in the XIB. Then you often use the NSNib or UINib to access the top-level objects of the nib element, so you can avoid view control and customize any structure you need in the NIB editor, and programmatically access the objects in the NIB as needed.

+1
source

In iOS 5, XIB is no longer recommended, use a storyboard instead. To simply answer your question, each top-level view requires the view manager to be responsible for it.

All sub-matrices can be output in your view controller and processed from there.

0
source

Source: https://habr.com/ru/post/1393825/


All Articles