简体   繁体   English

如何对NSString的NSTableColumn进行排序而忽略“ The”和“ A”?

[英]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. 我有一个正在使用的简单Core Data应用程序,用于显示我的电影收藏。 I'm using an NSTableView , with it's columns bound to attributes of my Core Data store through an NSArrayController object. 我正在使用NSTableView ,它的列通过NSArrayController对象绑定到我的Core Data存储的属性。 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). 我遇到的问题是字符串排序,它们进行排序,但是它是以标准字符串方式完成的,大写字母在小写字母之前(即Z在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. 除了使大小写排序正常工作外,我还希望在对字符串进行排序时能够忽略前缀“ The”或“ A”。

What is the best way to go about this in Objective-C/Cocoa? 在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. 在Interface Builder中,将每个表列的“ Sort Key字段设置为与要应用于托管对象的sortDescriptor相对应。

For each column that you want to ignore "A" and "the", you'll have to create an extra method on your managed objects. 对于您要忽略“ A”和“ the”的每一列,您必须在托管对象上创建一个额外的方法。 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". 如果您要排序的属性是title ,则创建一个名为cleanedTitle的新方法,该方法主要使用[self title]cleanedTitle “ a”和“ the”。 Then in Interface Builder, tell your table column to use the cleanedTitle sort key, instead of the title sort key. 然后在Interface Builder中,告诉您的表列使用cleanedTitle排序键,而不是title排序键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改NSTableColumn的背景? - How can I change the background of a NSTableColumn? 我可以使用选择器(就地)通过其子串对NSStrings的NSMutable数组进行排序吗? - can I sort NSMutable array of NSStrings by their substrings using the selector (in place)? 如何找到`NSTableColumn`的键来绘制排序指示器? - How to find the key of a `NSTableColumn` to draw the sort indicator? 如何对包含NSStrings的NSMutableArrays的NSMutableArray进行排序? - How can one sort an NSMutableArray of NSMutableArrays containing NSStrings? 如何使用大量NSString保持较低的内存使用率,或者如何释放NSString? - How can I keep memory usage low with a lot of NSStrings, or how do I release NSStrings? 我怎样才能将NSString与其他两个NSStrings进行比较 - How can i compare a NSString with two other NSStrings 将NSStrings转换为NSDates时如何避免语言问题? - How can I avoid language issues when converting NSStrings to NSDates? 按NSDate对NSTableColumn进行排序 - Sort NSTableColumn by NSDate 如何使用NSPredicate对NSString的NSArray进行排序? - How to sort NSArray of NSStrings using NSPredicate? 我可以使用NSStrings对XML馈送数组进行排序,就好像其中一些是数字一样吗? - Can I sort an XML-fed array with NSStrings as though some of them were numbers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM