Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of owner when using loadNibNamed?

Apple Doc says One of the most important objects in a nib file is the File’s Owner object , but it seems that's the File's owner in nib file , not the one set by LoadNibName method. I wonder what's the difference between them?

Here is an example:

I customize an alertView from xib and offer a static class method like this:

+(CustomAlert *)sharedAlert{
    CustomAlert *alert = [[[NSBundle mainBundle] loadNibNamed:@"CustomAlert" owner:nil options:nil]lastObject];
    return alert;
}

and I have a method to show alert on view

- (void)showInView:(UIView *)view{
    [view addSubview:self];
}

and in my viewController:

- (IBAction)buttonPressed:(id)sender{
    CustomAlert *alert = [CustomAlert sharedAlert];
    [alert showInView:self.view];
}

it works well in my situation,so is it necessary to set the owner in [[[NSBundle mainBundle] loadNibNamed: owner: options:?

like image 876
johnMa Avatar asked Nov 02 '22 08:11

johnMa


1 Answers

Let's say you have nib file with one tableview and the tableviews delegate and datasource is hooked up to "files owner" in interface builder. If you set files owner to any object, then that object will be the datasource and delegate of the tableview. This is valid for anything hooked up to the files owner.

like image 83
Taha Selim Bebek Avatar answered Nov 15 '22 05:11

Taha Selim Bebek