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 protected]>
To: charisse napeÿfffff1as <[email protected]>
Cc: [email protected]
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 protected]> 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&#39;ve always wanted before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to