Indexing your UITableViews
Improving the User Experience by Adding a Section Index
Once the amount of sections and rows in an UITableView
becomes too large, your users will have a hard time finding and scrolling to a particular entry. This problem can be solved by adding a section index to your tableview, so that the user can jump straight to a section with only one single tap. Apple uses such indices whenever they need to show long lists, e.g. in Music, Contacts or iTunes U.
In this article we will see how easy it is to add such an index.
Creating an UITableView
Before we add a section index, we first need to have an UITableView
with multiple rows. Let’s start by setting up a simple tableview.
// 1
— In this simple example we have added the tableview and set its dataSource
property via storyboard.
// 2
— We will use a property called sectionTitles
to hold all strings representing the titles of sections for the tableview and the section index. Here we just use all letters from “A” to “Z” but you may use any titles you want. You can even use whole words as you index elements, but this may look quite strange.
Note: You can also add a magnifying glass icon…