Re: [Solved] Custom NSPopUpButton and Cell
Re: [Solved] Custom NSPopUpButton and Cell
- Subject: Re: [Solved] Custom NSPopUpButton and Cell
- From: Philip Dow <email@hidden>
- Date: Sat, 17 Dec 2005 20:30:30 +0100
To add to the strangeness of the situation, I'm noticing that the
items in the menu lose the target and selector information I've set
in IB, while the menu retains its target and selector information.
Luckily, every item in the menu would have had the same target and
selector as the menu itself, so that in my action code, I can check
to see if the sender is a popup button and react according to the tag
of the selected item rather than the tag of the sender. Weird though.
-Phil
On Dec 17, 2005, at 8:21 PM, Uli Kusterer wrote:
Am 17.12.2005 um 12:27 schrieb Philip Dow:
Posted this guy about a week ago but didn't get a reply. Sat down
to it this morning and figured something out. I lose the IB menu
when I call
[self setCell:[[[PDPopUpButtonCell alloc] initTextCell:[self
title] pullsDown:[self pullsDown]] autorelease]];
in the initWithCoder method. I don't know why that's the case.
Turns out the solution is to save the menu, set my custom cell,
and reset the menu afterwards. I have no idea why this is
necessary. If anyone can shed some light on this...
- (id)initWithCoder:(NSCoder *)decoder {
if ( self = [super initWithCoder:decoder] ) {
NSMenu *tempMenu = [[self menu] copyWithZone:[self zone]];
[self setCell:[[[PDPopUpButtonCell alloc] initTextCell:[self
title] pullsDown:[self pullsDown]] autorelease]];
[self setMenu:tempMenu];
[tempMenu release];
}
return self;
}
My guess would be that the popup button cell owns the menu. When
you replace it with your cell subclass, the old cell is released,
releasing the menu as well. If you don't retain the menu yourself,
that would also cause the menu to go away.
Could that be the case?
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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