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