• 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: Programmatically selecting column header cell and triggering a sort
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programmatically selecting column header cell and triggering a sort


  • Subject: Re: Programmatically selecting column header cell and triggering a sort
  • From: Alex Reynolds <email@hidden>
  • Date: Mon, 20 Aug 2007 01:48:10 -0400

I was able to do the following on the NSTableView instance:

NSSortDescriptor *mySorter = [[NSSortDescriptor alloc] initWithKey: @"myKey" ascending: YES];
[myTableView setSortDescriptors:[NSArray arrayWithObject: mySorter]];
[mySorter release];


When I draw myTableView, the correct column is sorted. In this case, "myKey" is a row index, which is incremented from 0 onwards, as I generate the entity instances ("rows").

However, the problem is that, before I draw myTableView, I remove the NSTableColumn containing "myKey":

[myTableView removeTableColumn:[myTableView tableColumnWithIdentifier:@"myKey"]];

I do this in order to "hide" the column — I do not wish to show the row index.

The table is sorted, but not resortable: If I ever need to redraw myTableView (to draw a different set of objects) because this table column is no longer available, I can no longer use my sort descriptor.

I then, instead, tried to bind the "sortDescriptors" binding in the NSTableView to a NSArray object ("sortDescriptors") instantiated in my AppController:

mySorter = [[NSSortDescriptor alloc] initWithKey:@"myKey" ascending:YES];
sortDescriptors = [NSArray arrayWithObjects: mySorter];
[mySorter release];


This, unfortunately, prevents the data connected to myTableView from being displayed.

Is there another way to "fix" a sortDescriptor to a NSTableView, without requiring a (visible) column for that sort key?

Regards,
Alex

On Aug 19, 2007, at 11:20 AM, Andrew Merenbach wrote:

Hi, Alex,

If you're using bindings, you may wish to use -setSortDescriptors: on either the table view or, if it is bound to an array controller, on the array controller to which it is bound. With the array controller, you'll want to take the key of the sort descriptor from the name of the bound key (for instance, if you have bound a column of your table view to "[myArrayController].arrangedObjects.penguin", you'll want to set the sort descriptor to have the key "penguin").

Cheers,
	Andrew

On Aug 18, 2007, at 11:49 PM, Alex Reynolds wrote:

I have used the following call to select the column header cell of my table view:

[myTableView selectColumn:0 byExtendingSelection:NO];

This indeed selects the column header, but does not trigger a sort of the data in the table view, based on this column.

Is there a way to programmatically trigger a sort of the data in the table view?

Regards,
Alex

--------------------------------------------------------------------- -
Alex Reynolds, M. Biot.
217 Leidy Building / 6013
Department of Biology
University of Pennsylvania
Philadelphia, PA 19104


V: +1 215 573.2818
F: +1 215 898.8780
E: mailto:email@hidden
W: http://www.bio.upenn.edu/computing/

_______________________________________________

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


---------------------------------------------------------------------- Alex Reynolds, M. Biot. 217 Leidy Building / 6013 Department of Biology University of Pennsylvania Philadelphia, PA 19104

V: +1 215 573.2818
F: +1 215 898.8780
E: mailto:email@hidden
W: http://www.bio.upenn.edu/computing/

_______________________________________________

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: Programmatically selecting column header cell and triggering a sort
      • From: mmalc crawford <email@hidden>
References: 
 >Programmatically selecting column header cell and triggering a sort (From: Alex Reynolds <email@hidden>)
 >Re: Programmatically selecting column header cell and triggering a sort (From: Andrew Merenbach <email@hidden>)

  • Prev by Date: Re: Another Core Data + table view question
  • Next by Date: Re: Programmatically selecting column header cell and triggering a sort
  • Previous by thread: Re: Programmatically selecting column header cell and triggering a sort
  • Next by thread: Re: Programmatically selecting column header cell and triggering a sort
  • Index(es):
    • Date
    • Thread