按字母顺序自动分组 UITableView
有没有办法按字母顺序自动分组/自动分段我的 UITableView
?我有一个巨大的数组,显示得很好,但如果我有像 Contacts.app 中那样的部分,那就更好了。
最佳
–f
Is there a way to auto group/auto-section my UITableView
alphabetically? I have a huge array which is being displayed nicely, but it would be even better if I had the sections like in Contacts.app.
Best
–f
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先定义部分
,然后
按字母过滤
First of All Define sections
then
After that filter by alphabets
我有一个专门用于此目的的 Pod:
https://github.com/chrisladd/CGLAlphabetizer/
<代码>pod 'CGLAlphabetizer', '~> 0.1'
它创建一个数组字典,该数组以单个对象数组中的字母和任意 keyPath 为键。
alphabetizedDictionary = [CGLAlphabetizer AlphabetizedDictionaryFromObjects:anArray usingKeyPath:@"keyPath"];
因此,假设您有如下所示的模型对象:
的 tableViewController 实现可能如下所示:
您 进入太空:
I have a pod just for this:
https://github.com/chrisladd/CGLAlphabetizer/
pod 'CGLAlphabetizer', '~> 0.1'
It creates a dictionary of arrays keyed by letters of the alphabet from a single array of objects and an arbitrary keyPath.
alphabetizedDictionary = [CGLAlphabetizer alphabetizedDictionaryFromObjects:anArray usingKeyPath:@"keyPath"];
So, assuming you had the model object that looked like this:
Your tableViewController implementation might look something like this:
Populated with every human who has gone to space:
我做了以下操作:
AutoSectionTableViewDataSource.h
AutoSectionTableViewDataSource.m
然后在您的代码中:
i did the following:
AutoSectionTableViewDataSource.h
AutoSectionTableViewDataSource.m
and then in your code: