Re: NSToolbar problem
Re: NSToolbar problem
- Subject: Re: NSToolbar problem
- From: j o a r <email@hidden>
- Date: Tue, 11 May 2004 11:11:22 +0200
There are lots of little errors in your code...
On 2004-05-11, at 10.43, Fjolnir Asgeirsson wrote:
>
- (id)init
>
{
>
[super init];
>
>
(NSString *)toolbarIdentifier = @"toolbar";
>
(NSString *)playIdentifier = @"Play Game toolbar Item";
>
(NSString *)addIdentifier = @"Add Game toolbar Item";
>
(NSString *)delIdentifier = @"Remove Game toolbar Item";
>
(NSString *)modIdentifier = @"Edit Game toolbar Item";
>
(NSString *)docIdentifier = @"Help toolbar Item";
>
>
return self;
>
}
Why these weird casts?
Also, make sure that these variables are not re-used somewhere else -
and assigned some other value. That could explain your exceptions.
>
- (void) makeToolbar
>
{
>
(NSToolbar *)toolbar = [[[NSToolbar alloc]
>
initWithIdentifier:toolbarIdentifier] retain];
Why retain the newly allocated toolbar? Replace the retain with an
"autorelease".
>
- (NSToolbarItem *)toolbar:toolbar
>
itemForItemIdentifier:itemIdentifier
>
willBeInsertedIntoToolbar:(BOOL)flag
Why don't you use the same method signature as it's declared in the
header? You should always copy+paste the method name from the
documentation / header file.
>
{
>
(NSToolbarItem *)toolbarItem = [[[NSToolbarItem alloc]
>
initWithItemIdentifier:itemIdentifier] retain];
Same thing here. New objects are allocated with a retain count of 1.
Replace with "autorelease".
>
if ([itemIdentifier isEqualToString:addIdentifier])
>
{
>
// here I set the label & tooltip
>
[toolbarItem setToolTip:@"Add a new game"];
>
[toolbarItem setLabel:@"Add"];
>
[toolbarItem setPaletteLabel: @"Add Game"];
>
>
// Here the toolbar Item image is set
>
NSImage *addImage = [NSImage imageNamed:@"addItem.png"];
>
[toolbarItem setImage:(NSImage *)addImage];
You should not need to cast to NSImage here.
>
else
>
{
>
toolbarItem = nil;
>
}
This is a potential memory leak, as you're not autoreleasing the newly
created toolbar item.
>
// This is the allowed set of Items
>
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
>
{
>
return [NSArray arrayWithObjects:addIdentifier,
>
delIdentifier,
>
modIdentifier,
>
NSToolbarSpaceItemIdentifier,
>
NSToolbarFlexibleSpaceItemIdentifier,
>
docIdentifier];
>
}
>
>
// This is the default set of Items
>
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
>
{
>
return [NSArray arrayWithObjects:addIdentifier,
>
delIdentifier,
>
modIdentifier,
>
NSToolbarFlexibleSpaceItemIdentifier,
>
docIdentifier];
>
}
In both these cases you need to terminate the list of objects with
*nil*, it's in the documentation.
j o a r
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.