Re: How to get custom widgets into nib file window ?
Re: How to get custom widgets into nib file window ?
- Subject: Re: How to get custom widgets into nib file window ?
- From: Ricky Sharp <email@hidden>
- Date: Tue, 05 Apr 2005 13:10:52 -0500
On Tuesday, April 05, 2005, at 12:52PM, Robert Miller <email@hidden> wrote:
>Yes, the palette widgets show up correctly in the main palette
>window. I'd like to be able to drag the widget directly into the nib
>file window and then have an object automatically instantiated,
>similar to how CustomView in the main palette window behaves.
What exactly do you have in your palette's main window? Do you have NSImageViews that serve as "proxies" to your widgets or do you have the widgets themselves in it?
I've found it best to use NSImageViews to serve as proxies. You can really hose yourself if putting the actual widget in the palette's main window such that the widget contains a defect. I've had IB lock up or crash on numerous occassions because of this.
Anyhow, here's typically what I do...
In MyPalette.h:
@interface MyPalette : IBPalette
{
IBOutlet NSImageView* widgetProxy;
MyWidget* widget;
}
In MyPalette.m:
- (void)finishInstantiate
{
widget = [[[MyWidget alloc] initWithFrame:NSMakeRect (...)] autorealease];
// or use whatever appropriate designated initializer you want
[widget setAttributeOne:...];
// set up any attributes for your widget here. For example, my palettes provide many different
// forms of the same widget; just with different properties.
[self associateObject:widget ofType:IBViewPboardType withView:widgetProxy];
}
Note that I've left out numerous other methods (e.g. specifying the names of inspectors, being a resource dragging delegate, etc.). But what is shown above should now allow you to drag items off your palette.
In your palette's nib file, add an NSImageView to your main palette window and supply an appropriate image (typically a screenshot or some other rendering of your widget). Connect up the widgetProxy outlet.
Also make sure that your widget fully conforms to NSCoding. If not, and you drag that widget from the palette, nothing will appear in your nib's window (and sometimes IB will hang). This is because the encodeWithCoder is send to the palette's item (to encode it). Then, a new instance of the widget is created and initialized with initWithCoder (using the data that was encoded in the previous step).
You may also need to conform to NSCopying (e.g. your widgets are cells that will live in matricies).
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
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