Well, even after distilling into a tiny demo, I still can't figure this one out. A popup menu attached to a regular button works fine. But when using it as an NSTableHeaderCell, it keeps tracking the mouse even after it's closed.

How can one work around this?

Here's a 30-second movie:

   http://sheepsystems.com/engineering/projects/KOT/KeepOnTrackin.mov

and the tiny demo project (56 KB):

   http://sheepsystems.com/engineering/projects/KOT/KeepOnTrackin.zip

and finally, for those who would rather just look at the code:


#import "KOTAppDel.h"


@implementation KOTAppDel

// Start a ticking timer.  When the timer pauses, we'll know
// that one of our popup menus is tracking the mouse.
- (void)applicationDidFinishLaunching:(NSNotification*)note {
    [NSTimer scheduledTimerWithTimeInterval:1.0
                                     target:self
                                   selector:@selector(tick)
                                   userInfo:nil
                                    repeats:YES] ;
}

- (void)tick {
    NSLog(@"tick") ;
}

- (void)logChoice:(id)sender {
    NSLog(@"You clicked \"%...@\"", [sender title]) ;
}

- (NSMenu*)makeMenu {
    NSMenu* menu = [[NSMenu alloc] init] ;
    NSArray* choices = [NSArray arrayWithObjects:
                        @"Me",
                        @"Oh",
                        @"My",
                        nil] ;
    for (NSString* choice in choices) {
        NSMenuItem* item ;
        item = [[NSMenuItem alloc] init] ;
        [item setRepresentedObject:choice] ;
        [item setTitle:choice] ;
        [item setAction:@selector(logChoice:)] ;
        [menu addItem:item] ;
        [item release] ;
    }

    return [menu autorelease] ;
}

- (void)awakeFromNib {
    [table setDelegate:self] ;
}

// Action method for the button
- (IBAction)buttonClicked:(id)sender {
    NSPopUpButtonCell* popUpCell = [[NSPopUpButtonCell alloc] init] ;

    [popUpCell setMenu:[self makeMenu]] ;
    [popUpCell performClickWithFrame:NSZeroRect
                                 inView:sender] ;
    [popUpCell release] ;
}

// Table View delegate method.
// A little more complicated since we have to dig into the
// parts of the table, and assign it as a header cell.
- (void)               tableView:(NSTableView*)tableView
  mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn {
    NSTableHeaderView *headerView = [tableView headerView] ;

    NSPopUpButtonCell* popUpCell = [[NSPopUpButtonCell alloc] init] ;
    [tableColumn setHeaderCell:popUpCell] ;

    [popUpCell setMenu:[self makeMenu]] ;
    [popUpCell performClickWithFrame:NSZeroRect
                          inView:headerView] ;
    [popUpCell release] ;
}

@end


_______________________________________________

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