• 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
Loading project images in an IB Palette
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Loading project images in an IB Palette


  • Subject: Loading project images in an IB Palette
  • From: Ricky Sharp <email@hidden>
  • Date: Sat, 27 Nov 2004 23:57:08 -0600


On Nov 27, 2004, at 11:25 PM, Ricky Sharp wrote:

Right now I'm doing some trial-and-error stuff regarding loading images from a parent Xcode project. While I do have code that can hunt down and load the images, such code isn't being invoked when my nib document opens. I'm hoping to find a solution by listening to IBDidOpenDocumentNotification notifications.

Well, I got a working solution that knows how to deal with PDF files (the code should ultimately work with any image type).


In my IBPalette subclass, I added these two methods:

+ (void)initialize
{
	[[NSNotificationCenter defaultCenter] addObserver:self
		selector:@selector(iiDocumentDidOpen:)
		name:IBDidOpenDocumentNotification object:nil];
}

+ (void)iiDocumentDidOpen:(NSNotification*)aNotification
{
id <IBDocuments> theDocument = [aNotification object];

if (theDocument != nil)
{
id<IBProjects> theProject = [theDocument project];

if (theProject != nil)
{
NSArray* resources = [theProject filesForFileType:IBProjectResourcesFileType];

if (resources != nil)
{
NSEnumerator* enumerator;
id element;
NSString* elementString;
NSRange range;
NSString* nameKey = @".pdf";
NSImage* image = nil;

enumerator = [resources objectEnumerator];

while ((element = [enumerator nextObject]) != nil)
{
elementString = [element path];
range = [elementString rangeOfString:nameKey];

if (range.location != NSNotFound)
{
image = [[NSImage alloc] initWithContentsOfFile:elementString];

if (image != nil)
{
NSArray* thePathComponents = [elementString pathComponents];
NSArray* theFileComponents = [[thePathComponents lastObject] componentsSeparatedByString:@"."];

[image setName:[theFileComponents objectAtIndex:0]];
}
}
}
}
}
}
}



Basically, whenever you double-click on a nib in your Xcode project, this code is called when the IB document opens. It then scans the entire Xcode project's Resource folder for PDF files. When found, an NSImage is created and it is named. The name I chose is the actual file name sans the extension.


This now allows me to edit my custom widgets with images not contained in the nib itself, but in the parent Xcode project.

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >IBPalette refuses to bring up inspector (From: Ricky Sharp <email@hidden>)
 >Re: IBPalette refuses to bring up inspector [SOLVED] (From: Ricky Sharp <email@hidden>)
 >Re: IBPalette refuses to bring up inspector [SOLVED] (From: "M. Uli Kusterer" <email@hidden>)
 >Re: IBPalette refuses to bring up inspector [SOLVED] (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: IBPalette refuses to bring up inspector [SOLVED]
  • Next by Date: Re: [ANN] Value Converter
  • Previous by thread: Re: IBPalette refuses to bring up inspector [SOLVED]
  • Next by thread: Nib files and outlets
  • Index(es):
    • Date
    • Thread