Re: Dynamically loading NIB files into sheets
Re: Dynamically loading NIB files into sheets
- Subject: Re: Dynamically loading NIB files into sheets
- From: Sebastian Celis <email@hidden>
- Date: Sun, 14 Apr 2002 15:42:50 -0500
First off, thanks for all of your help! Also, sorry for my long-winded
questions. I am relatively new to Cocoa, but I think I am beginning to
understand... It's just taking time, practice, and lots of reading over
the Apple documentation. I really appreciate all of the help you gave
me.
On Saturday, April 13, 2002, at 06:22 PM, j o a r wrote:
>
On Saturday, April 13, 2002, at 11:22 , Sebastian Celis wrote:
>
>
> I've thought about creating a SheetController class that each Document
>
> has an instance of, and then having this SheetController class have
>
> instances of SheetControllerA, SheetControllerB, and so on for the
>
> number of sheets I have... but I'm having trouble implementing it
>
> (specifically with regard to what class calls what method and what the
>
> syntax of the final method to display the sheet should be).
>
>
The SheetController could be a subclass of NSObject, responsible for
>
instantiating SheetWindowControllers matching the provided sheetID's,
>
and keeping track of them - once loaded, they should be kept around to
>
be able to be re-used.
>
>
The SheetWindowController could be a subclass to NSWindowController,
>
with just the methods added for it to be the delegate of the sheet,
>
et.c. as outlined above.
>
>
What do you think? I'm not sure you need an extra layer of objects
>
using the SheetWindowControllers - you could also just put the
>
appropriate outlets in the SheetController and then use [NSBundle
>
loadNibNamed:@""] and load the sheets there - but it's up to you.
Here is my SheetWindowController code:
@implementation SheetWindowController // subclass of NSWindowController
- (id)initWithWindowNibName:(NSString *)name
{
return [super initWithWindowNibName:name];
}
@end
and my SheetController code:
@interface SheetController : NSObject
{
// Keeps track of all of the sheets that have been loaded
NSMutableDictionary *theSheets;
}
- (SheetWindowController *)sheetControllerForIdentifier:(NSString
*)sheetIdentifier;
@end
- (SheetWindowController *)sheetControllerForIdentifier:(NSString
*)sheetIdentifier
{
SheetWindowController* aSheetController
= [theSheets objectForKey:sheetIdentifier];
// If the sheet has been loaded before, don't load it again,
// just return it from the dictionary
if(aSheetController != nil)
{
return aSheetController;
}
// Otherwise, load it, add it to the dictionary, and return it.
else
{
// The following line is giving me compiler warnings:
// SheetController.m:35: warning: cannot find class (factory)
method.
// SheetController.m:35: warning: return type for `alloc'
defaults to id
// Why isn't it working?
aSheetController = [[SheetWindowController alloc]
initWithWindowNibName:sheetIdentifier];
[theSheets setObject:aSheetController forKey:sheetIdentifier];
return aSheetController;
}
}
And finally, we have the code for the button that displays a sheet:
// Is called when a button is pushed on the document window.
- (IBAction)openSheet:(id)sender
{
// I have this next line working fine
NSString *sheetID = [self sheetIdentifierForTag:[[thePopUpButton
selectedItem] tag]];
SheetWindowController *sheetCtrl = [sheetController
sheetControllerForIdentifier:sheetID];
[NSApp beginSheet:[sheetCtrl window]
modalForWindow:ReferenceDocumentWindow
modalDelegate:sheetCtrl
didEndSelector:[sheetCtrl selector]
contextInfo:nil];
}
Now, I have a couple of questions other than the ones found in the
comments above...
You said that the SheetWindowController should have "methods added for
it to be the delegate of the sheet, etc. as outlined above." How and
why would I do this? Is this just so that I can tell when the sheet is
closing so that I can run the code that uses whatever information the
user entered into the sheet?
Also, does this have anything to do with the line:
[NSApp beginSheet...
{
...
didEndSelector:[sheetCtrl selector]
...
}
which is giving me an error?
Do I need to add a variable "selector" to the SheetWindowController
class that refers to the method that should run when the sheet closes?
Again, thanks so much for your help.
Take care,
Sebastian Celis
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.