如何根据姓氏创建索引表视图
如果您可以找到基于姓氏的索引表视图的教程,例如“联系人”应用程序,那就太好了。我查遍了所有地方,但找不到姓氏。
If you could find a tutorial for an indexed table view based on last name like the "Contacts" app, that would be great. I've search all around but can't find one on last names.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你使用核心数据存储你的联系人。您可能有一个实体“Person”,其属性包括名字、姓氏、地址等。
您应该专门为实体“Person”创建一个 NSManagedObject 的子类。在此类中,您添加一个仅返回姓氏的第一个字母的方法。如果您有 NSFetchedResultsController,您可以应用这些部分的路径名。在那里,您只需写出返回第一个字母的方法的名称即可。然后,表视图应按姓氏的第一个字母进行分区,就像在联系人中一样。
现在,您应该实现方法
You 返回一个数组,其中包含将出现在右侧的所有索引标题。假设您的联系人是“Steve Jobs”和“Jony Ive”,则将有两个部分和两个索引标题“I”和“J”。您不必将整个字母表中的所有字母放入数组中,只需将那些您真正需要的字母放入即可。
I guess you store your contacts using core data. You probably have a entity "Person" with attributes first name, last name, address etc.
You should make a subclass of NSManagedObject specifically for the entity "Person". In this class, you add a method that returns only the first letter of the last name. If you have a NSFetchedResultsController you can apply the path name for the sections. There you just write the name of exactly that method that returns the first letter. The table view should then be sectioned by the last name's first letter like in contacts.
Now, you should implement the method
You return a array that contains all the index titles which will appear on the right. Let's say if your contacts are "Steve Jobs" and "Jony Ive", there would be two sections and two index titles "I" and "J". You don't have to put all letters of the whole alphabet in the array, just those that you really need.