PDA

View Full Version : Question on File's owner




MacRohde
Feb 2, 2009, 04:45 AM
I'm not sure if I totally understand the concept of File's owner. So I have a question about this.

As I understand it, the File's owner is the link from a nib to the outside.
And one way is to set the controller of the nib to the file's owner. Is that correct?

For example, if I have a menu item that opens a dialog from another nib, then I can respond to a click on that menu item like so in order to show a dialog for converting numbers between different base systems:

-(IBAction) showConvertNumberToBaseDialog:(id)sender {
convertNumberToBaseController = [[ConvertNumberToBaseController alloc] init];

if (![NSBundle loadNibNamed:@"ConvertNumberToBase"
owner:convertNumberToBaseController])
{
NSLog(@"Error loading Nib for ConvertToBase dialog!");
}
}

So here an instance of the ConvertNumberToBaseController is set as the file's owner of the corresponding ConvertNumberToBase nib.

Would that be correct?



MacRohde
Feb 2, 2009, 08:49 AM
Ok., so after some research I can answer my own question. I can do what I has done - which is to use a single controller as both the coordinating controller and the mediating controller.

Usually it is best not to combine both roles into a single controller, as I have done, but for some situations it is suitable.

More can be read here:

The Model-View-Controller Design Pattern (http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/chapter_5_section_4.html)