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

CHAPTER 8: Introduction to Table Views

235

row if you find that necessary. Go ahead and add this method to your controller class, just before @end:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 70;

}

We’ve just told the table view to set the row height for all rows to 70 pixels tall. Compile and run, and your table’s rows should be much taller now (see Figure 8–14).

Figure 8–14. Changing the row size using the delegate

There are more tasks that the delegate handles, but most of the remaining ones come into play when you start working with hierarchical data, which we’ll do in the next chapter. To learn more, use the documentation browser to explore the UITableViewDelegate protocol and see what other methods are available.

Customizing Table View Cells

You can do a lot with table views right out of the box, but often, you will want to format the data for each row in ways that simply aren’t supported by UITableViewCell directly. In those cases, there are two basic approaches: one that involves adding subviews to

www.it-ebooks.info

236

CHAPTER 8: Introduction to Table Views

UITableViewCell programmatically when creating the cell, and a second that involves loading a set of subviews from a nib file. Let’s look at both techniques.

Adding Subviews to the Table View Cell

To show how to use custom cells, we’re going to create a new application with another table view. In each row, we’ll display two lines of information along with two labels (see Figure 8–15). Our application will display the name and color of a series of potentially familiar computer models, and we’ll show both of those pieces of information in the same table cell by adding subviews to the table view cell.

Figure 8–15. Adding subviews to the table view cell can give you multiline rows.

Create a new Xcode project using the Single View Application template. Name the project Cells, and use the same settings as your last project. Click BIDViewController.xib to edit the nib file in Interface Builder.

Add a Table View to the main view, use the connections inspector to set its delegate and data source to File’s Owner as we did for the Simple Table application, and then save the nib.

www.it-ebooks.info

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