I have a view with three rows and want to set referencing outlets for them programmatically – how is this done?
Share
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.
IBOutletis just a marker so Interface Builder knows which instance variables are intended to be assigned objects from your nibs. It doesn’t really make sense to talk about assigning outlets automatically – their entire purpose is for the opposite approach. TheIBstands for Interface Builder.If you want to assign objects in a nib to instance variables, you’ll need to step over the view hierarchy and have some way of identifying the objects you want to collect.
You can step over the view hierarchy by accessing
self.viewin a view controller. If there are objects in the nib that aren’t subviews of the main view, you won’t be able to access them. You could load the nib withUINibinstead of relying on the built-in functionality to get these objects.You can identify the objects in several different ways depending on your needs. You can assign integers to a view’s
tagproperty in Interface Builder. You can look at the views that you know will be at a certain point in the hierarchy. You can look at views of a particular type. Or you can mix and match – for example, theUIButtonsubclass of the main view with an even tag.If you are laying out your views with Interface Builder, it is almost always easiest to simply assign the views to outlets with Interface Builder instead.