• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Named images in linked frameworks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Named images in linked frameworks
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: How do I give a set of methods to some objects but not others?
  • Next by Date: Re: How do I give a set of methods to some objects but not others?
  • Previous by thread: [ann] New Cocoa App Project Template
  • Next by thread: Re: Named images in linked frameworks
  • Index(es):
    • Date
    • Thread