I have a xib with a root view that is a UIView subclass. How should this view get references to the child views I declared in Interface Builder?
Obviously a ViewController can be wired up with outlets, but what about a UIView?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Outlets are properties of UIViewController objects which (almost always) refer to instances of UIView objects (or subclasses of UIView).
A UIViewController has a single UIView which, when the UIViewController is loaded with
initWithNibNamed:, is the contents of the XIB file. You can set up outlets in the UIViewController and then tie them to the various subviews in your XIB by dragging to the “File’s Owner” item in the list, or by dragging to the code in Xcode’s assistant editor.If you want to use only code, there are several options. One way, is to directly access a view based on its
tagproperty. For example:Another approach to consider is that a UIView has a property called
subviews, which is an array of sub views. You can iterate through them and access the views as necessary. To differentiate between them, you can do several things, depending on the situation. You can set tags on the views, and just use those.Alternatively, if you’re looking for a specific kind of view, say, a UISwitch, something like this might work in simple cases:
If you’re using tags, you can set them in code, or use Interface Builder.