• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem on NSPopUpButton Class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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&#39;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

References: 
 >Problem on NSPopUpButton Class (From: charisse napeÿfffff1as <email@hidden>)
 >Re: Problem on NSPopUpButton Class (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: NSTableView retain count problem
  • Next by Date: [Moderator] Re: [OT] Re: A question of legality...
  • Previous by thread: Re: Problem on NSPopUpButton Class
  • Next by thread: Re: Problem on NSPopUpButton Class
  • Index(es):
    • Date
    • Thread