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

218

CHAPTER 8: Introduction to Table Views

Figure 8–1. Though they all look different, the Settings, iPod, and YouTube applications use table views to display their data.

Table View Basics

Tables display lists of data. Each item in a table’s list is a row. iOS tables can have an unlimited number of rows, constrained only by the amount of available memory. iOS tables can be only one column wide.

Table Views and Table View Cells

A table view is the view object that displays a table’s data and is an instance of the class UITableView. Each visible row of the table is implemented by the class UITableViewCell. So, a table view is the object that displays the visible part of a table, and a table view cell is responsible for displaying a single row of the table (see Figure 8–2).

www.it-ebooks.info

CHAPTER 8: Introduction to Table Views

219

Figure 8–2. Each table view is an instance of UITableView, and each visible row is an instance of UITableViewCell.

Table views are not responsible for storing your table’s data. They store only enough data to draw the rows that are currently visible. Table views get their configuration data from an object that conforms to the UITableViewDelegate protocol and their row data from an object that conforms to the UITableViewDataSource protocol. You’ll see how all this works when we get into our sample programs later in the chapter.

As mentioned, all tables are implemented as a single column. But the YouTube application, shown on the right side of Figure 8–1, does give the appearance of having at least two columns, perhaps even three if you count the icons. But no, each row in the table is represented by a single UITableViewCell. Each UITableViewCell object can be configured with an image, some text, and an optional accessory icon, which is a small icon on the right side (we’ll cover accessory icons in detail in the next chapter).

You can put even more data in a cell if you need to by adding subviews to UITableViewCell, using one of two basic techniques: adding subviews programmatically when creating the cell, or loading them from a nib file. You can lay out the table view cell out in any way you like and include any subviews you desire. So, the single-column limitation is far less limiting than it probably sounds at first. If this is confusing, don’t worry—we’ll show you how to use both of these techniques in this chapter.

www.it-ebooks.info

220

CHAPTER 8: Introduction to Table Views

Grouped and Plain Tables

Table views come in two basic styles:

Grouped: Each group in a grouped table is a set of rows embedded in a rounded rectangle, as shown in the leftmost picture in Figure 8–3. Note that a grouped table can consist of a single group.

Plain: Plain is the default style. Any table that doesn’t feature rounded rectangles is a plain table view. When an index is used, this style is also referred to as indexed.

If your data source provides the necessary information, the table view will let the user navigate your list using an index that is displayed down the right side. Figure 8–3 shows a grouped table, a plain table without an index, and a plain table with an index (an indexed table).

Figure 8–3. The same table view displayed as a grouped table (left), a plain table without an index (middle), and a plain table with an index, also called an indexed table (right)

Each division of your table is known to your data source as a section. In a grouped table, each group is a section. In an indexed table, each indexed grouping of data is a section. For example, in the indexed table shown in Figure 8–3, all the names beginning with A would be one section, those beginning with B another, and so on.

www.it-ebooks.info

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