I have a NSTableView that is bound using Cocoa Bindings. One column of that table is an image cell. Total images I’m using are only 2, so they can be repeated on each row.
How can I sort my NSTableView, to display first rows that have image1.jpg and, after that, rows that have image2.jpg?
I can’t control it when I’m adding rows to the underlying array because they can be added in random order.
In the XIB editor, you can double click the table column and select the “Attributes” pane and set a sort key.
If you’re using Core Data, you’d probably have to add something like an “imageName” property to your entity, and set the sort key to
imageNameand the selector tocompare:If not, you can just set the sort key to
image.nameand the selector tocompare:and it should work fine.That allows the user to select the table column header to sort the image column. If you want sorting to happen automatically you can set the sort descriptor in code, with the same keys I listed above.
Edit: Do you have your XIB set up like this: