Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting file owner of a xib file

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).

like image 601
user2054339 Avatar asked Jul 30 '13 11:07

user2054339


People also ask

What is file owner in Swift?

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 ...

What is file's owner?

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.

What is file's owner in Xcode?

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.


2 Answers

You did not specify the file owner twice:

  • The first time (in the XIB file) you specified the type of the file owner; this is necessary for the Interface Builder to know which outlets it can connect.
  • The second time (in the Objective C code) you specified the instance of the owner. This is necessary at runtime to know the object into which the outlets are connected.
like image 77
Sergey Kalinichenko Avatar answered Nov 15 '22 09:11

Sergey Kalinichenko


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.

like image 34
Wain Avatar answered Nov 15 '22 09:11

Wain