I created a generic nib file “MyGenericView.xib” which owner (for reusability purposes) is UIViewController.
In my classes I can successfully load the view
[[NSBundle mainBundle] loadNibNamed:@"MyGenericView" owner:self options:nil];
However, I have defined a label as sub-object in the same Generic View.
How can I access it and overload (for example) label.text?
In a normal situation, I would set the file Owner of my Nib to my specific Controller, and connect an IBOutlet to the file owner.
As the file owner (in my generic case) is UIViewController, this it is not possible.
Thanks in advance
In the interface builder, set the label’s tag to, let’s say, 1. You can find the tag field in the attributes inspector, View section. Then use viewWithTag: method:
Additionally, if you ever happen to have the similar problem with table cells, I recommend using UINib class. This class is great when you don’t need to delegate any actions to the file owner, you can instantiate your objects without any owner at all.