Re: Custom component fails to load images by name in a IBPlugin
Re: Custom component fails to load images by name in a IBPlugin
- Subject: Re: Custom component fails to load images by name in a IBPlugin
- From: "Dalzhim Dalzhim" <email@hidden>
- Date: Mon, 22 Sep 2008 18:51:11 -0400
2008/9/22 Jonathan Hess
<email@hidden>
Hey Dalzhim -
If you want to work with your Interface Builder outside of building and running your plug-in project, you need to do an "sudo xcodebuild install" from your project directory and then install the built bits. By default, Xcode will layout the distribution root for the built projects in /tmp in a folder that starts with the name of your projects and ends with dst. If you examine this folder, you'll see that it's a sparse root for /. It will contain all of the files your project built that should be installed and the will have a path relative to their final destination. If your project was named MyProject, you could install them with 'sudo ditto /tmp/MyProject.dst/ /'. That ditto command would overlay the contents of the distribution root on to /, effectively installing them. At this point if you launched Interface Builder from the finder, you'd be able to load your plug-in and work with it. Working with your plug-in in this manner would be different than working with it after having pressed build and run from the plug-in project in Xcode. Pressing build and run will build and run the latest sources. When running IB from the finder, you'll be running against the installed framework, and possibly the installed plug-in depending on which on you loaded into Interface Builder last.
Hello Jon,
I have seen some discussions where this "sudo xcodebuild install" procedure was explained but I thought this was meant for a permanent installation of a plugin (which I meant to do much later in my development process). From what I have read in the Interface Builder Plug-In Programming Guide, I thought it was possible to dynamically load plug-ins when they were in the Resources folder of a linked-in framework.
« When building your framework, be sure to include your Interface Builder plug-in in the
Resources
directory of the framework. When the user loads a nib file, Interface
Builder checks for any linked-in frameworks in the associated Xcode
project. If those frameworks contain a bundle with an
.ibplugin
extension, Interface Builder automatically loads that plug-in before it opens the nib file. »
http://developer.apple.com/documentation/DeveloperTools/Conceptual/IBPlugInGuide/DesigningControlsViews/chapter_4_section_5.html#//apple_ref/doc/uid/TP40004323-CH3-DontLinkElementID_33
When your code is in IB, and is working with images there are a couple of subtleties to consider. First, is the image a project image coming from the user, or is it a framework image coming from your framework, or both. If your widget has an image property, that you would like the user to be able to fill out in the inspector, then you should obtain the image via -[IBDocument documentImageNamed:]. The reason you need to go through that message and not -[NSImage imageNamed:] is that -[NSImage imageNamed:] works on a global set of names. In Interface Builder the user is free to work on many documents were each document has a different set of images and names. Unfortunately, Interface Builder doesn't offer a way for plug-ins to integrate content into the set of per-document named images. So, if you're framework has an image and you want that image to show up in the library and be available to regular cocoa controls, then unfortunately, there isn't a supported way to do that. However, if you just want to integrate the users images into your custom controls, you should be able to do that with -[IBDocument documentImageNamed:].
Jon Hess
I have tried using -[IBDocument documentImageNamed:] without success as I have never succeeded on getting an instance of IBDocument. I have tried getting an instance using +[IBDocument documentForObject:] from within MyComponent but the only result I have ever had was nil. I only used those two lines from within the setter method for the image property of MyComponent and upon every modification of this property through the inspector view I have made, debugging showed I never had a IBDocument instance.
IBDocument* doc = [IBDocument documentForObject:self];
NSImage* image = [doc documentImageNamed:imageName];
What am I doing wrong?
Thanks for your help!
regards
-Dalzhim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden