Re: NSPopUpButtonCell Keeps on Trackin'! Demo, Movie
Re: NSPopUpButtonCell Keeps on Trackin'! Demo, Movie
- Subject: Re: NSPopUpButtonCell Keeps on Trackin'! Demo, Movie
- From: Jerry Krinock <email@hidden>
- Date: Sun, 26 Apr 2009 07:41:37 -0700
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@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