• 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: TableView and context menus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TableView and context menus


  • Subject: Re: TableView and context menus
  • From: Ondra Cada <email@hidden>
  • Date: Tue, 25 Sep 2001 16:45:23 +0200

Sven,

>>>>>> Sven A. Schmidt (SAS) wrote at Tue, 25 Sep 2001 15:36:47 +0200:
SAS> {
SAS> NSEnumerator *iter = [ [ crTable tableColumns ]
SAS> objectEnumerator ];
SAS> NSTableColumn *col;
SAS> NSMenu *menu = [ [ NSMenu alloc ] init ];
SAS> [ menu addItemWithTitle: NSLocalizedString( @"Run now", @"Run
SAS> now context menu item" )
SAS> action: @selector(runSelectedCommand) keyEquivalent: @"" ];
SAS> while ( col = [ iter nextObject ] )
SAS> [ [ col dataCell ] setMenu: menu ];
SAS> [ menu release ];
SAS> }

SAS> What am I doing wrong?

Presuming that each table cell has its own data cell, which "stays" where
the table cell is. That's not true (perhaps you've used NSMatrix, which works
that way, before). The NSColumn, though, has just _one_ data cell, which
stays "nowhere", but is used to draw any item (with changing coordinates).

For your trivial case of one menu for whole table it should be possible to
set it directly to the TableView (even in InterfaceBuilder without any
programming).

Should you need specific menus for different columns, or even for different
cells, you'd have to do something like this:

@implementation NSTableView (OCSPopUpMenuForSpecificCell)
-(NSMenu*)menuForEvent:(NSEvent*)evt {
NSPoint pt=[self convertPoint:[evt locationInWindow] fromView:nil];
int column=[self columnAtPoint:pt],row=[self rowAtPoint:pt];
if (column>=0 && row>=0 && [[self delegate]
respondsToSelector:@selector(menuForTableColumn:row:)])
return [[self delegate] menuForTableColumn:[[self tableColumns]
objectAtIndex:column] row:row];
return nil;
}
@end

Here the actual menu is provided by a delegate (that's how I use it in some
of my applications, from whose implementation I've copied the excerpt), but
of course you can hardcode the menu there as well.
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc


  • Follow-Ups:
    • Re: TableView and context menus
      • From: John Hörnkvist <email@hidden>
    • Re: TableView and context menus
      • From: John Hörnkvist <email@hidden>
References: 
 >TableView and context menus (From: "Sven A. Schmidt" <email@hidden>)

  • Prev by Date: Re: Loading a nib window and making it key
  • Next by Date: Re: Enumerated lists - (Sorry for the stupid questions.)
  • Previous by thread: TableView and context menus
  • Next by thread: Re: TableView and context menus
  • Index(es):
    • Date
    • Thread