简体   繁体   中英

How can I sort an NSTableColumn of NSStrings ignoring “The ” and “A ”?

I've got a simple Core Data application that I'm working on to display my movie collection. I'm using an NSTableView , with it's columns bound to attributes of my Core Data store through an NSArrayController object. At this point the columns sort fine(for numeric values) when the column headers are clicked on.

The issue I'm having is with the String sorting, they sort, however it's done in standard string fashion, with Uppercase letters preceding lowercase(ie Z before a). In addition to getting the case sorting to work properly, I would like to be able to ignore a prefix of "The " or "A " when sorting the strings.

What is the best way to go about this in Objective-C/Cocoa?

In Interface Builder, you set the Sort Key field of each table column to correspond to which sortDescriptor you want applied to your managed objects.

For each column that you want to ignore "A" and "the", you'll have to create an extra method on your managed objects. If the property you're sorting is title , then create a new method called cleanedTitle that basically takes [self title] and strips out "a" and "the". Then in Interface Builder, tell your table column to use the cleanedTitle sort key, instead of the title sort key.

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