可可方法返回当前语言环境字母表中所有字母的列表?
我目前正在尝试实现 UITableView
与 委托和数据源 尽可能地复制发现 的功能ABAddressBookUI
框架的 ABPeoplePickerNavigationController
类,但增加了一次选择多个联系人的功能(如通过向相应的 UITableViewCell
)。
一切工作正常,除了为 UITableView
,应由 数据源方法:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
显然,我可以返回一个 NSArray
包含 NSStrings
A、B、C ...Z,但我理想情况下,像此方法一样返回当前语言环境的所有字母(如果适用,大写)字母的数组。
一个有希望的线索是:
[[
NSLocale
currentLocale] objectForKey:@"NSLocaleExemplarCharacterSet"]
但我找不到任何关于此的重要文档,它返回 NSCharacterSet
,我无法从中提取实际字符(如果我能做到这一点,那么 NSCharacterSet 的 capitalizedLetterCharacterSet
也可能是一个有希望的起点)。
我还运行了 otool -tV
在 AddressBookUI
框架,它显示了对函数 ABAddressBookCopySectionIndices()
的调用,其中包含 ABAddressBookRef
可以传递以获得我正在寻找的内容......本地化字母表的 CFArray。 但是,它是一个私有函数,所以我不能在我的应用程序中使用它。
那么,有人知道 Cocoa Touch 是否支持此功能吗?如果没有,是否有关于 ABAddressBookCopyIndices() 如何发挥其魔力的任何想法?我怀疑 International Components for Unicode 库很可能掌握着关键,但我还没有(到目前为止) )熟悉其功能...
I'm currently trying to implement a UITableView
with a delegate and data source that replicates, as closely as possible, the functionality found the ABAddressBookUI
framework's ABPeoplePickerNavigationController
class, but with the added ability to select multiple contacts at once (as indicated by adding/removing an accessory view to the appropriate UITableViewCell
).
Everything is working fine, with the exception of providing localized "section index titles" (the letters that appear in the scroll overlay to the right of the screen) for the UITableView
, as should be returned by the data source method:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
Obviously, I could just return an NSArray
containing the NSStrings
A, B, C ...Z, but I'd ideally like this method to return an array of all of the (uppercase, where applicable) letters of the alphabet of the current locale.
One promising lead was:
[[
NSLocale
currentLocale ] objectForKey:@"NSLocaleExemplarCharacterSet" ]
But I can't find any significant documentation on this and it returns an NSCharacterSet
, from which I've been unable to extract the actual characters (if I could do that, then NSCharacterSet's capitalizedLetterCharacterSet
could also be a promising starting point).
I've also run an otool -tV
on the AddressBookUI
framework, which revealed a call to the function ABAddressBookCopySectionIndices()
, into which an ABAddressBookRef
can be passed to obtain exactly what I'm looking for… a CFArray of the localized alphabet. However, it's a private function, so I can't use it in my app.
So, does anybody know whether Cocoa Touch supports this functionality? And, if not, are there any ideas as to how ABAddressBookCopyIndices()
is working its magic? I suspect the International Components for Unicode library may well hold the key, but I'm not (as yet) familiar with its capabilities...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请不要假设部分索引应该是“大写字母”。这仅对某些欧洲语言有效。例如,日语或中文没有大写字母的概念,他们只是有太多的字母开头,但有一组通常在现实世界的词典或现实世界的地址簿中使用的习惯标签。
相反,请使用标准 UILocalizedIndexedCollation。它正是您所需要的。
Please don't assume that the section indices should be "capital letters". That's only valid for some European languages. E.g. Japanese or Chinese don't have the concept of capital letters, they just have too many letters to start with, but there's a customary set of labels usually used in real-world dictionaries or real-world address books.
Instead, use the standard UILocalizedIndexedCollation. It gives exactly what you need.
无聊了,为你写了这篇文章
,它将为你提供该系列中的一系列角色。
Got bored and wrote this up for you
That will give you an array of the characters in the set.
这个可以帮助你得到你想要的东西
this one help you to get what exactly you want