osx - NSTableView - how to get automatic and manual sorting working together? -
i have nstableview
in myviewcontroller
, have array controller bound it. want able sort clicking table column headers , should auto-sort. auto-sort set sort descriptors binding of array controller in ib following:
bind to: myviewcontroller model key path: customsortdescriptors
in myviewcontroller class i've added:
var customsortdescriptors:[nssortdescriptor] { let sd = nssortdescriptor(key: "string", ascending: true, selector: "localizedstandardcompare:"); return [sd] }
and related table column in ib i've set:
sort key: string selector: caseinsensitivecompare:
this works ok until click on table column header upon error thrown:
error setting value key path customsortdescriptors of object nsautounbinder: 0x60000005e060 - nonretaining proxy myapp.myviewcontroller: 0x6000000e6600 (from bound object nsarraycontroller: 0x6000001c0b40[entity: generateddata, number of selected objects: 0]): [myapp.myviewcontroller 0x6000000e6600 setvalue:forundefinedkey:]: class not key value coding-compliant key customsortdescriptors.
i'm not sure why error. can tell me wrong? why myviewcontroller not key value coding-compliant? aren't nsviews , nsviewcontrollers compliant default?
besides sorting works without problems error thrown in xcode , want eliminate that.
i damned reason error property read-only. adding setter, or better yet, change code simply:
var customsortdescriptors = [nssortdescriptor(key: "string", ascending: true, selector: "localizedstandardcompare:")];
fixed error , both, automatic , manual sorting works.
Comments
Post a Comment