Class

UILocalizedIndexedCollation

An object that organizes, sorts, and localizes the data for a table view that has a section index.

Declaration

@interface UILocalizedIndexedCollation : NSObject

Overview

Use a UILocalizedIndexedCollation object in conjunction with your table's data source object to sort and manage the data in an indexed table view. An index is an ideal way for users to navigate a table view containing sequential content. For example, the Contacts app sorts contacts alphabetically and displays an index for navigating those contacts quickly. You use the collation object as the source of the table's section titles and index titles in your table view. You also use it to sort items in each section of your table.

To prepare the data for a section index, create an indexed-collation object and call sectionForObject:collationStringSelector: for each model object to be indexed. That method determines the section in which each of these objects should appear and returns an integer that identifies the section. The table-view controller then puts each object in a local array for its section. For each section array, the controller calls the sortedArrayFromArray:collationStringSelector: method to sort all of the objects in the section. The indexed-collation object is now the data store that the table-view controller uses to provide section-index data to the table view, as shown in the following example code.

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] objectAtIndex:section];
}
 
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}
 
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index];
}

Topics

Getting the Shared Instance

+ currentCollation

Returns an indexed-collation instance for the current table view.

Preparing the Sections and Section Indexes

- sectionForObject:collationStringSelector:

Returns an integer identifying the section in which a model object belongs.

- sortedArrayFromArray:collationStringSelector:

Sorts the objects within a section by their localized titles.

Providing Section Index Data to the Table View

sectionTitles

Returns the list of section titles for the table view.

sectionIndexTitles

Returns the list of section-index titles for the table view

- sectionForSectionIndexTitleAtIndex:

Returns the section that the table view should scroll to for the given index title.

Relationships

Inherits From

See Also

Data

Filling a Table with Data

Create and configure cells for your table dynamically using a data source object, or provide them statically from your storyboard.

UITableViewDataSource

The methods adopted by the object you use to manage data and provide cells for a table view.

UITableViewDataSourcePrefetching

A protocol that provides advance warning of the data requirements for a table view, allowing you to start potentially long-running data operations early.

UIDataSourceTranslating

An advanced interface for managing a data source object.

UIRefreshControl

A standard control that can initiate the refreshing of a scroll view’s contents.