Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning iOS5 Development.pdf
Скачиваний:
7
Добавлен:
09.05.2015
Размер:
15.6 Mб
Скачать

254

CHAPTER 8: Introduction to Table Views

Adding an Index

One problem with our current table is the sheer number of rows. There are 2,000 names in this list. Your finger will get awfully tired looking for Zachariah or Zayne, not to mention Zoie.

One solution to this problem is to add an index down the right side of the table view. Now that we’ve set our table view style back to Plain, that’s relatively easy to do. Add the following method to the bottom of BIDViewController.m, just above the @end:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return keys;

}

Yep, that’s it. In this method, the delegate is asking for an array of the values to display in the index. You must have more than one section in your table view to use the index, and the entries in this array must correspond to those sections. The returned array must have the same number of entries as you have sections, and the values must correspond to the appropriate section. In other words, the first item in this array will take the user to the first section, which is section 0.

Compile and run the app again, and you’ll have yourself a nice index (see Figure 8–24).

Figure 8–24. The table view with an index

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]