如何对NSStrings的NSTableColumn进行排序忽略“The”和“A”。 [英] How can I sort an NSTableColumn of NSStrings ignoring "The " and "A "?

查看:186
本文介绍了如何对NSStrings的NSTableColumn进行排序忽略“The”和“A”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Core Data应用程序,我正在努力显示我的电影收藏。我使用一个 NSTableView ,它的列绑定到我的Core Data存储的属性通过一个 NSArrayController 对象。此时,当列标题被点击时,列排序精细(对于数值)。



我遇到的问题是使用字符串排序,他们排序,但是它是以标准字符串方式完成的,大写字母在小写之前(即在a之前的Z)。除了使案例排序正常工作外,我还希望在排序字符串时忽略The或A的前缀。



是在Objective-C / Cocoa中最好的解决方法。

解决方案

在Interface Builder中, $ c> Sort Key 字段,以便与要应用于您的托管对象的sortDescriptor对应。



想要忽略A和the,你必须在被管理对象上创建一个额外的方法。如果要排序的属性为 title ,则创建一个名为 washedTitle 的新方法,基本上需要 [self title] ,并删除a和the。然后在Interface Builder中,告诉你的表列使用 washedTitle 排序键,而不是 title 排序键。 / p>

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(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.

这篇关于如何对NSStrings的NSTableColumn进行排序忽略“The”和“A”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆