• 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
NSTableView not setting -clickedRow, -clickedColumn as it should
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTableView not setting -clickedRow, -clickedColumn as it should


  • Subject: NSTableView not setting -clickedRow, -clickedColumn as it should
  • From: Graham Cox <email@hidden>
  • Date: Wed, 08 Aug 2012 15:55:39 +1000


According to the release notes for 10.7, NSTableView should now support contextual menus at the individual cell level:

> NSTableView/NSOutlineView - Contextual menu support
>
> NSTableView and NSOutlineView now have better contextual menu support. Please see the DragNDropOutlineView demo application for an example of how to properly do contextual menus with a TableView.
>
> The key thing to note is that clickedRow and clickedColumn will now both be valid when a contextual menu is popped up. In addition, one can dynamically set the popup menu for a particular cell/column in the delegate method willDisplayCell:. NSTableView handles this by properly overriding menuForEvent:, setting the clickedRow/clickedColumn, and calling [NSCell menuForEvent:inRect:ofView] to find the correct menu. If no menu was returned, the menu for the NSTableView will be used. If one right clicks on a selection of items, all the items are highlighted. One should check to see if clickedRow is one of the selected rows, and if it is then do the menu operation on all the selected rows. The clickedRow and clickedColumn properties will still be valid when the action is sent from the NSMenuItem.
>


But when I implement the method in my custom cell, though it's being called correctly,  -clickedRow and -clickedColumn are returning -1. As a result I can't tell which row I right-clicked, so I can't process the menu further. Has this change been revoked in 10.8 (which I'm using at the moment)?

Code:

- (NSMenu*)		menuForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)view
{
	NSMenu* menu = nil;

	if([view respondsToSelector:@selector(delegate)])
	{
		id tvDelegate = [(id)view delegate];

		if([view isKindOfClass:[NSTableView class]] && [tvDelegate respondsToSelector:@selector(contextualMenuForTableView:tableColumn:row:)])
		{
			NSTableView*	tv = (NSTableView*) view;
			NSInteger		row, column;

			row = [tv clickedRow];
			column = [tv clickedColumn];




--Graham




_______________________________________________

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

  • Follow-Ups:
    • Re: NSTableView not setting -clickedRow, -clickedColumn as it should
      • From: Corbin Dunn <email@hidden>
    • Re: NSTableView not setting -clickedRow, -clickedColumn as it should
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: UITableView with multiple UIScrollView each having its own zoom scale?
  • Next by Date: Re: UITableView with multiple UIScrollView each having its own zoom scale?
  • Previous by thread: Re: UITableView with multiple UIScrollView each having its own zoom scale?
  • Next by thread: Re: NSTableView not setting -clickedRow, -clickedColumn as it should
  • Index(es):
    • Date
    • Thread