sharkyenergy sharkyenergy - 1 month ago 15
Objective-C Question

disable "create sort descriptor" for column programmatically

i have a NSTableview that uses cocoa bindings. i need to disable sorting in the table and to do so i found following text here on stackoverflow:


If you use Cocoa bindings to manage the data, the sort descriptor is generated by the table column and set to the NSArrayController. To stop it, just open the inspector of the binding of the table column, select value, and uncheck "Creates Sort Descriptor."


this is working great, but there are a few columns that are added at Runtime and i would need to do the same thing at Runtime programmatically. Could somebody please point me in the right direction? an example or a tutorial or whatever could help me to do this at Runtime. basically all i need to do is disable sorting for a column created at Runtime.

Answer

If you are setting up your bindings on the arraycontroller programmatically, you should be able to pass in extra binding options like so.

    NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
    [bindingOptions setObject:[NSNumber numberWithBool:NO]
                       forKey:NSCreatesSortDescriptorBindingOption];
        [column bind:@"value" toObject:self.arrayController withKeyPath:[NSString stringWithFormat:@"arrangedObjects.%@",c.key] options:bindingOptions];
Comments