Re: Problem on NSPopUpButton Class
Re: Problem on NSPopUpButton Class
- Subject: Re: Problem on NSPopUpButton Class
- From: charisse napeÿfffff1as <email@hidden>
- Date: Mon, 23 Nov 2009 22:30:43 -0800 (PST)
Below is my code
#import "MyPopupButton.h"
@implementation MyPopupButton
- (void) awakeFromNib
{
MyPopupButtonCell *newCell = [[MyPopupButtonCell alloc] init];
[newCell setAction:[[self cell] action]];
[newCell setTarget:[[self cell] target]];
[newCell setControlSize:[[self cell] controlSize]];
[newCell setFont:[[self cell] font]];
[self setCell:newCell];
[newCell release];
[self setAutoenablesItems:NO];
[self initMyPopupButton : 0];
}
#pragma mark ----- methods -----
- (void) initMyPopupButton : (int) selectedItem
{
[self removeAllItems];
NSMenuItem* newMenuItem;
newMenuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]
initWithTitle:@"Item1"
action:NULL
keyEquivalent:@""];
[[self menu] addItem:newMenuItem];
[newMenuItem release];
newMenuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]
initWithTitle:@"Item2"
action:NULL
keyEquivalent:@""];
[[self menu] addItem:newMenuItem];
[newMenuItem release];
[[self menu] addItem:[NSMenuItem separatorItem]];
newMenuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]
initWithTitle:@"App1"
action:NULL
keyEquivalent:@""];
[[self menu] addItem:newMenuItem];
[newMenuItem release];
newMenuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]
initWithTitle:@"App2"
action:NULL
keyEquivalent:@""];
[[self menu] addItem:newMenuItem];
[newMenuItem release];
[self selectItemAtIndex : 0];
}
- (void) myListChanged : (NSNotification*) aNotification
{
int selectedIndex = [[aNotification object] intValue];
if (selectedIndex < 0) {
selectedIndex = 0;
} else {
selectedIndex += 3;
}
[self initMyPopupButton : selectedIndex];
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
@end
@implementation MyPopupButtonCell
#if __LP64__
- (void) selectItemAtIndex : (NSInteger) index
#else
- (void) selectItemAtIndex : (int) index
#endif
{
if (index + 2 <= [self numberOfItems]) {
[super selectItemAtIndex:index];
}
}
@end
________________________________
From: Kyle Sluder <email@hidden>
To: charisse napeÿfffff1as <email@hidden>
Cc: email@hidden
Sent: Tuesday, November 24, 2009 12:54:26
Subject: Re: Problem on NSPopUpButton Class
On Mon, Nov 23, 2009 at 1:27 AM, charisse napeÿfffff1as
<email@hidden> wrote:
> Problem: subclassed popup button cannot be disabled sometimes.
> Scenario: Instead of using NSPopUpButton directly, I created a subclass of NSPopUpButton named MyPopUpButton because there are other things I needed
> done in that subclass.
You need to describe and post the code for the "other things" you did
in your subclass.
--Kyle Sluder
Get your new Email address!
Grab the Email name you've always wanted before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden