开发者

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

开发者 https://www.devze.com 2022-12-29 10:41 出处:网络
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 NSArrayC

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 Up开发者_JAVA百科percase letters preceding lowercase(i.e. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号