Re: Responding from a delegate?
Re: Responding from a delegate?
- Subject: Re: Responding from a delegate?
- From: Sam Thorne <email@hidden>
- Date: Thu, 15 Apr 2004 20:10:48 +0100
Hi,
On second thought, do you really mean an action of one of you
interface elements, or do you mean an actual delegate method?
Could you provide some source code which gives you trouble?
Thank you both for the help, here's where I'm getting confused; as I
understand it from Ondra's post, I need to set an instance var in the
GameToolbar delegate that points back to the GameWindowController, so
that when the IBAction in GameToolbar is triggered the window
controller can then tell it's window to open a drawer.
I've got this working fine without using the delegate class, but I'm
curious as to how I'd do it with delegation.
I'm guessing something along the lines of
toolbarDelegate = [[GameToolbar alloc] init];
[toolbarDelegate delegator:self];
and then setting up delegator as an accessor in the interface of
GameToolbar, would this be right?
Anyway, here's the code:
//////////////
This is the window controller for the documents:
#import "GameWindowController.h"
@implementation GameWindowController
- (void) awakeFromNib
{
toolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
toolbarDelegate = [[GameToolbar alloc] init];
[toolbar setDelegate: toolbarDelegate];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[[self window] setToolbar:[toolbar autorelease]];
}
-(void) windowDidClose
{
[toolbarDelegate release];
}
@end
//////////////////////////////
And this is the toolbar delegate:
#import <Cocoa/Cocoa.h>
@interface GameToolbar : NSObject
{
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag;
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
- (BOOL)validateToolbarItem:(NSToolbarItem*)toolbarItem;
-(IBAction) attachComponents:(id)sender;
-(IBAction) viewGame:(id)sender;
@end
_______________________________________________
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.