Hi, I have a NSTableView with 3 columns. I can sort using any of the colunms by clicking on the column header. Here is my issue though: I am presorting the array and then loading it in NSTableView so the initial TableView is already sorted by the values in one of the 3 columns. Now when I click on the column headers, i can resort and the small ascending/descending image ( triangle) appears indicating how the sort order is. What I want is, to be able to display this ascendingimage triangle in the column header right at the start when the NSTableView is loaded the first time, for the column based on which I have already sorted the Array. Thanks in advance :)
Thanks Peter and cb160. So I added this in my refreshList method:
The *lastColumn parameter has the right identifier if i display it using NSLog, but still that triangle image does not get loaded when the table loads data the first time. Is there something I am missing here ? My table View is setup like this:
-(IBAction)refreshList:(id)sender
{
//setup array here and sort the array based on one column. This column has
identifier 'col1' and it works as expected
// trying to set the sortindicator image for the column here
NSTableColumn *lastColumn;
lastColumn = [aTableView tableColumnWithIdentifier:@"col1"];
[aTableView setIndicatorImage:[NSImage imageNamed:@"NSDescendingSortIndicator"]
inTableColumn:lastColumn];
[aTable reloadData];
}
- (int) numberOfRowsInTableView:(NSTableView *)aTable
{ // return count of array
}
- (id)tableView:(NSTableView *)aTable objectValueForTableColumn: (NSTableColumn *)
tableColumn row:(int)row
{
//set up arrays here to load data in each column
}
- (void)tableView:(NSTableView *)aTableView sortDescriptorsDidChange:(NSArray
*)oldDescriptors
{
//sort here when column headers are clicked
}