Named images in linked frameworks
Named images in linked frameworks
- Subject: Named images in linked frameworks
- From: Claudio Procida <email@hidden>
- Date: Fri, 24 Nov 2006 20:21:31 +0100
I read in the Cocoa Drawing Guide that before using an image resource
present in a bundle, I have to load it and explicitly set its name.
So I've added this code in the framework's main class +initialize:
+ (void)initialize
{
NSBundle *localBundle = [NSBundle bundleForClass:[self class]];
// Manually register named image resources
NSImage *closeButton = [[NSImage alloc] initByReferencingFile:
[localBundle pathForResource:@"closebtn" ofType:@"tif"]];
[closeButton setName:@"closebtn"];
//[closeButton autorelease];
NSImage *closeButtonHighlight = [[NSImage alloc]
initByReferencingFile:[localBundle
pathForResource:@"closebtn_highlight" ofType:@"tif"]];
[closeButtonHighlight setName:@"closebtn_highlight"];
//[closeButtonHighlight autorelease];
NSImage *closeButtonPressed = [[NSImage alloc] initByReferencingFile:
[localBundle pathForResource:@"closebtn_pressed" ofType:@"tif"]];
[closeButtonPressed setName:@"closebtn_pressed"];
//[closeButtonPressed autorelease];
NSImage *resizer = [[NSImage alloc] initByReferencingFile:
[localBundle pathForResource:@"growbox" ofType:@"png"]];
[resizer setName:@"growbox"];
//[resizer autorelease];
}
This works fine.
What troubles me is that if I uncomment the -autorelease messages,
the resources suddenly disappear during runtime. So I have to leave
those objects lying around during execution. It's just a few KBytes,
but I wonder if is that the correct way of doing thingsā¢ ??
--
Claudio Procida
Emeraldion Lodge
http://www.emeraldion.it
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden