如何按字母顺序创建分段/分组表视图 [英] How to create sectioned/grouped table view alphabetically

查看:116
本文介绍了如何按字母顺序创建分段/分组表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个解析大型xml文件并将数据导入表视图的应用程序。用户可以在搜索栏中输入文本以搜索表格视图。

I am creating an app that parses huge xml file and gets the data into table view. The user can enter text into search bar to search the table view.

现在,我想将表视图变成一个按字母顺序分组的分段视图。正常表格视图是巨大的,搜索功能包括在内我想知道如何将表格视图分成几个部分......任何教程或来源都会有很大的帮助...

Now, i want to make the table view into a sectioned one that is grouped alphbetically. Sine the table view is huge and the search functionality is included i want to know how to make the table view into sections... Any tutorials or source will be of great help...

推荐答案

您必须使用配置为部分索引的表视图

请参阅 iOS视图编程指南

You must use a table view configured as an section index
See Table View Programming Guide for iOS

[...]索引列表是普通样式的表格视图通过三种UITableViewDataSource方法专门配置:

[...]An indexed list is a table view in the plain style that is specially configured through three UITableViewDataSource methods:


  • sectionIndexTitlesForTableView:

  • tableView:titleForHeaderInSection:

  • tableView:sectionForSectionIndexTitle:atIndex:

  • sectionIndexTitlesForTableView:
  • tableView:titleForHeaderInSection:
  • tableView:sectionForSectionIndexTitle:atIndex:

T.第一个方法返回一个字符串数组用作索引条目(按顺序),第二个方法将这些索引字符串映射到表视图节的标题(它们不必相同),并且第三种方法返回与用户在索引中点击的条目相关的节索引。

The first method returns an array of the strings to use as the index entries (in order), the second method maps these index strings to the titles of the table-view’s sections (they don’t have to be the same), and the third method returns the section index related to the entry the user tapped in the index.

用于填充索引列表的数据应组织为反映这种索引模型。具体来说,您需要构建一个数组数组。每个内部数组对应于表中的一个部分;根据主流排序方案对区段阵列进行排序(或整理)在外部阵列内,该排序方案通常是字母方案(例如,A到Z)。此外,每个节数组中的项目都已排序。您可以自己构建和排序这个数组数组,但幸运的是,UILocalizedIndexedCollat​​ion类使构建和排序这些数据结构以及向表视图提供数据的任务变得更加容易。该类还根据当前的本地化来整理数组中的项目。

The data that that you use to populate an indexed list should be organized to reflect this indexing model. Specifically, you need to build an array of arrays. Each inner array corresponds to a section in the table; section arrays are sorted (or collated) within the outer array according to the prevailing ordering scheme, which is often an alphabetical scheme (for example, A through Z). Additionally, the items in each section array are sorted. You could build and sort this array of arrays yourself, but fortunately the UILocalizedIndexedCollation class makes the tasks of building and sorting these data structures and providing data to the table view much easier. The class also collates items in the arrays according to the current localization.

这篇关于如何按字母顺序创建分段/分组表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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