Let's say that I have a UIView that I would like to reuse in several view controllers, given that this is a pretty general UIView object with a high reuse value (like a UITextField or UISegmentedControl ). In my opinion, it would be much easier to reuse this UIView if I wrote a UIView in the code, instead of doing XIB using Interface Builder. I came to this conclusion, because if the UIView is written in code, I can simply initialize a new instance of this UIView in any controller of the form:
MyGreatReusableView *greatReusableView = [[MyGreatReusableView alloc] initWithFrame:CGRectMake(...)];
... and then directly access the properties and attributes of this UIView, as well as with UIView controls such as UITextField with its properties .text , .textColor , etc.
However, if I create a UIView as an XIB, it must be bound (via a File Owner or IBOutlet in the View object in the XIB) to a specific view controller and therefore can only be used in that view controller. In addition, I can only access the properties of controls on the XIB using IBOutlets that are connected to this view controller.
I think I completely misunderstood something regarding XIB files, as this is apparently very limited! If someone can provide clarification regarding the possibility of reusing XIB files in several view controllers and, if so, provide an example of a code-based solution and an XIB-based solution, I would be very grateful.
Thanks in advance for your help!
source share