简体   繁体   中英

NSArrayController, custom sorting

I have an NSTableView, with each column bound to the appropriate value in an NSArrayController. One of the columns contains an NSImageCell, displaying an image.

I want to sort by this column, but obviously sorting by an image's object value is not what I want. I actually sort by the combination of other fields, but I can't work out how to set this up. When I click on the column header for the field in question, the sort arrows do not appear.

I have NSSortDescriptors applied to the NSArrayController to sort the other columns, but when sorting, it appears that all the NSSortDescriptors have access to is the object value of the table cell.

I need to sort by a comparison method on the object that the object value is a property of. Is this possible? I've already subclassed NSArrayController, and it seems like somewhere in there would be a good bet, but I can't find anything in the documentation that helps.

Ok, so I solved this by just creating the table column in IB and setting the sort key there. Bit of a workaround but it ended up whittling down my code a little, so I can't complain. It does seem strange that you can't set a sort key programatically though. At least, not via any method I can find.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM