IB inspector won't load [Really Solved]
IB inspector won't load [Really Solved]
- Subject: IB inspector won't load [Really Solved]
- From: Ricky Sharp <email@hidden>
- Date: Mon, 29 Nov 2004 09:16:21 -0600
In a prior thread, I outlined a major problem in my IB palletes such that inspectors wouldn't be shown for my widgets.
Specifically, my widgets were always returning nil from their accessors. While I was able to get past the problem, I really didn't know specifically what was done to solve it.
This morning, I created a fresh IB palette with a derived NSView (IIGraphic). It started out with a single NSColor* ivar. I coded everything by hand, and all worked well.
I then added the remaining ivars and used Accessorizer to generate all accessor and archive code. The revised object then no longer allowed me to inspect it. Accessors were once more returning nil.
I then instrumented all methods in IIGraphic to see what was really going on. Why I didn't do this over the holiday weekend with my other troublesome widgets is beyond me; perhaps coding over a holiday weekend is a bad thing :)
Anyhow, here's the trace I got:
IB launched and my palette is loaded. The palette has a single instance of IIGraphic on it:
(<IIGraphic: 0x450be40>) initWithFrame:{78.000000,65.000000,114.000000,58.000000}
(<IIGraphic: 0x450be40>) setColor:NSCalibratedRGBColorSpace 0 0 1 1
(<IIGraphic: 0x450be40>) setImageName:
(<IIGraphic: 0x450be40>) setImageFraction:1.000000
(<IIGraphic: 0x450be40>) setNumberOfTileRows:1
(<IIGraphic: 0x450be40>) setNumberOfTileColumns:1
(<IIGraphic: 0x450be40>) setSelectedTileIndex:0
(<IIGraphic: 0x450be40>) setCompositeIntoSuperview:0
(<IIGraphic: 0x450be40>) setCompositedIntoSuperview:0
(<IIGraphic: 0x450be40>) drawRect:{0.000000,0.000000,114.000000,58.000000}
(<IIGraphic: 0x450be40>) color
At this point, all is well.
I then drag the IIGraphic palette item to a window and get this...
(<IIGraphic: 0x450be40>) encodeWithCoder:<NSKeyedArchiver: 0x45620f0>
Note that we are encoding the instance that lives on the palette, then initializing a new instance as follows...
(<IIGraphic: 0x42dc860>) initWithCoder:<NSKeyedUnarchiver: 0x31e1c0>
(<IIGraphic: 0x42dc860>) setColor:(null)
(<IIGraphic: 0x42dc860>) setImageName:(null)
(<IIGraphic: 0x42dc860>) setImageFraction:0.000000
(<IIGraphic: 0x42dc860>) setNumberOfTileRows:0
(<IIGraphic: 0x42dc860>) setNumberOfTileColumns:0
(<IIGraphic: 0x42dc860>) setSelectedTileIndex:0
(<IIGraphic: 0x42dc860>) setCompositeIntoSuperview:0
(<IIGraphic: 0x42dc860>) setCompositedIntoSuperview:0
(<IIGraphic: 0x4541ef0>) initWithCoder:<NSKeyedUnarchiver: 0x4546ce0>
(<IIGraphic: 0x4541ef0>) setColor:(null)
(<IIGraphic: 0x4541ef0>) setImageName:(null)
(<IIGraphic: 0x4541ef0>) setImageFraction:0.000000
(<IIGraphic: 0x4541ef0>) setNumberOfTileRows:0
(<IIGraphic: 0x4541ef0>) setNumberOfTileColumns:0
(<IIGraphic: 0x4541ef0>) setSelectedTileIndex:0
(<IIGraphic: 0x4541ef0>) setCompositeIntoSuperview:0
(<IIGraphic: 0x4541ef0>) setCompositedIntoSuperview:0
(<IIGraphic: 0x4541ef0>) color
*** Assertion failure in -[NSColorWell setColor:], AppKit.subproj/NSColorWell.m:425
I'm not sure at this time why there are two instances being created, but the second instance seems to drive the inspector. That's where I ultimately get the NSColorWell assertion.
The root of the problem is in the encodeWithCoder method since it isn't encoding my object and thus all ivars are nil or zero.
Here's why...
Accesorizer's generated code for encodeWithCoder: will currently do this:
- (void)encodeWithCoder:(NSCoder *)coder
{
if ([super encodeWithCoder:coder]) {
[coder encodeObject:[self myAttribute] forKey:@"MyAttribute"];
}
}
But encodeWithCoder: doesn't have a return value. Thus, none of the statements in the 'if' are executed. And because the object isn't encoded properly, when initWithCoder is called, there is nothing to decode and so everything remains nil or zero.
The fix was to ensure that encodeWithCoder: is as follows:
- (void)encodeWithCoder:(NSCoder *)coder
{
[super encodeWithCoder:coder];
[coder encodeObject:[self myAttribute] forKey:@"MyAttribute"];
}
I've already alerted Kevin about this.
Please note that I'm not trying to shed any bad light on Accessorizer. It really is a very useful tool and has already saved me from typing pages of code. If you are using the Keyed-Archiving code gen, you'll need to fix up encodeWithCoder:
--
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