Note that there are some explanatory texts on larger screens.

plurals
  1. POReuse of code-based UIViews compared with XIBs
    primarykey
    data
    text
    <p>Say that I have a UIView which I would like to re-use in multiple view controllers, given that it is a fairly generic UIView object with high re-usability value (like a <code>UITextField</code> or <code>UISegmentedControl</code> object). From my understanding it would be much easier to reuse this UIView if I wrote the UIView in code, rather than making a XIB using Interface Builder. I have reached this conclusion because if the UIView is written in code then I can simply initialize a new instance of that UIView in any view controller:</p> <pre><code>MyGreatReusableView *greatReusableView = [[MyGreatReusableView alloc] initWithFrame:CGRectMake(...)]; </code></pre> <p>...and then directly access the properties and attributes of that UIView, just like with the stock UIView controls such as <code>UITextField</code> with it's <code>.text</code>, <code>.textColor</code>, etc. properties.</p> <p>However, if I create the UIView as a XIB then it must be tied (through either the File's Owner or an IBOutlet on the View object in the XIB) to a specific view controller, and therefore can only be used in that view controller. Furthermore, I can only access the properties of controls on the XIB using the IBOutlets which are connected to that view controller.</p> <p>I am thinking that I have completely misunderstood something with regards to XIB files, as this does seem to be quite a limitation! If someone could provide clarification on whether it is possible to re-use XIB files in multiple view controllers and, if so, provide an example of a code-based solution vs. a XIB-based solution I would be very much appreciative.</p> <p>Thanks in advance for any assistance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload