• 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: doubleClick and tableView Trouble
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: doubleClick and tableView Trouble


  • Subject: Re: doubleClick and tableView Trouble
  • From: Glenn Zelniker <email@hidden>
  • Date: Wed, 1 Feb 2006 16:39:37 -0500


On Feb 1, 2006, at 4:04 PM, Charles Moore Jr. wrote:

i'm having an odd problem with double-clicking within a tableView.

i have an NSTableView bound to an NSMutableArray full of objects. i currently have doubleClick performing the following when called:

Object *myObject=[myObjectArray objectAtIndex:[myTableView clickedRow]];

i then send myObject to another module via a notification like this:

NSDictionary *d=[NSDictionary dictionaryWithObject:myObject forKey:@"objectSelected"];
NSNotification *n=[NSNotification notificationWithName:@"objectWasSelected" object:self userInfo:d];
[[NSNotificationCenter defaultCenter] postNotification:n];


the second module then does something brilliant with the selected object.

this all works beautifully.

however, if i then SORT the table-view, things break down.


if i have three objects 'A', 'B', and 'C' at row indices 0,1, and 2 respectively - doubleClicking on A correctly selects A.


however, if i then sort the tableView so that now the objects are presented as 'C', 'B', and 'A', double-clicking on 'A' pulls up object 'C'. selecting 'A' pulls up 'C'. it appears that, while the tableview is successfully re-sorting how the objects appear, the underlying bound array still thinks they are in the previous order.

i've worked around this so far by simply disabling sorting but i would like to find out what i'm doing wrong.

I'm assuming you have things bound through an NSArrayController and KVO coding, no? If that's the case, you actually want to do selection through your array controller as in:


NSArray *sortedArray = [myArrayController arrangeObjects:myObjectArray];

		int row = [myTableView clickedRow];

		Object *myObject = [sortedArray objectAtIndex:row];

Now you should have the correct object.

HTH,

GZ

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: doubleClick and tableView Trouble
      • From: "Charles Moore Jr." <email@hidden>
References: 
 >doubleClick and tableView Trouble (From: "Charles Moore Jr." <email@hidden>)

  • Prev by Date: Use (if any) of NSImageView bindings placeholders?
  • Next by Date: Re: Using C++ iostreams for file IO in Cocoa
  • Previous by thread: doubleClick and tableView Trouble
  • Next by thread: Re: doubleClick and tableView Trouble
  • Index(es):
    • Date
    • Thread