I have an NSTableView that I am trying to sort. The data source is an NSMutableArray which contains instances of custom classes.
-(void)tableView:(NSTableView *)tableView sortDescriptorsDidChange: (NSArray *)oldDescriptors
I am using the above so that I can track when the user presses a header of the table. I am using the following method to do the sorting:
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"make" ascending:bool_asc_desc] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [ads_printers_array sortedArrayUsingDescriptors:sortDescriptors];
What I would like to know is how can I pass on the table column which was pressed? This would allow me to change the initWithKey:@”make” (using if statements) so that I can sort according to the header clicked.
Thanks.
P.S. I have tried the following:
if ([ads_rdp_driver_table selectedColumn] == tc_make)
with ads_rdp_driver_table being my NSTableView and tc_make being an NSTableColumn which I have defined. However, I am getting this error:
ISO C++ forbids comparison between pointer and integer
I guess this could work if I could figure out the error.
The
selectedColumnmethod of an NSTableView returns the index of the selected column (not a pointer to it), which is why you are getting the compile error. To get the actual column, try something like this instead (code my contain errors, Im typing verbatim):