Hi I am reading a book where I had to deal with such situation.
I created a XIB file named HeaderView.xib.
Then I connected the File Owner
of this XIB
file to ItemsViewController
. All is fine so far. I also connected
some outlets of the ItemsViewController with views on the XIB.
Now, in the ItemsViewController
I had to call such code:
- (UIView *)headerView
{
// If we haven't loaded the headerView yet...
if (!headerView) {
// Load HeaderView.xib
[[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil];
}
return headerView;
}
Code above would set headerView
outlet of ItemsViewController
point to the corresponding
view on the XIB file (the one I made connections with on XIB file).
My question is, why did I have to, two times, specify the owner? (e.g., once in the XIB as I mentioned in the start of this port, and second time, above in the code, e.g., owner: self
).
The File Owner proxy is an Interface Builder construct to represent potential instances of objects that will instantiate an instance of the object graph that allows the user to connect action methods and outlets defined in the object graph to the File Owner instance that loads the NIB/XIB (again, there can be more than ...
Initially, a file's owner is identified by the user ID of the person who created the file. The owner of a file determines who may read, write (modify), or execute the file.
The File owner is the object that loads the nib, i.e. that object which receives the message loadNibNamed: or initWithNibName: . If you want to access any objects in the nib after loading it, you can set an outlet in the file owner.
You did not specify the file owner twice:
Specifying the owner in the XIB tells Xcode what the controller understands (what outlets it has) so that it can offer the connections to you. This is at a class level.
Specifying the owner in code tells the unarchiving process which instance of the controller is actually going to fulfil that role and should therefore have the connections established to the new instance(s) which are unarchived from the NIB.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With