tailieunhanh - Ebook IOS programming - The big nerd ranch guide (5th edition): Part 2

(BQ) Part 2 book "IOS programming - The big nerd ranch guide" has contents: Subclassing UITable view cell, uinavigationcontroller, stack views, touch events and uiresponder, uigesturerecognizer and uimenucontroller, web services, collection views, core data relationships,.and other contents. | 11 Subclassing UITableViewCell A UITableView displays a list of UITableViewCell objects. For many applications, the basic cell with its textLabel, detailTextLabel, and imageView is sufficient. However, when you need a cell with more detail or a different layout, you subclass UITableViewCell. In this chapter, you will create a subclass of UITableViewCell named ItemCell that will display Item instances more effectively. Each of these cells will show an Item’s name, its value in dollars, and its serial number (Figure ). Figure Homepwner with subclassed table view cells You customize the appearance of UITableViewCell subclasses by adding subviews to its contentView. Adding subviews to the contentView instead of directly to the cell itself is important because the cell will resize its contentView at certain times. For example, when a table view enters editing mode, the contentView resizes itself to make room for the editing controls (Figure ). If you added subviews directly to the UITableViewCell, these editing controls would obscure the subviews. The cell cannot adjust its size when entering edit mode (it must remain the width of the table view), but the contentView can resize, and it does. Figure Table view cell layout in standard and editing mode Creating ItemCell Create a new Swift file named ItemCell. In , define ItemCell as a UITableViewCell subclass. i mport Foundation i mport UIKit c lass ItemCell: UITableViewCell { } The easiest way to configure a UITableViewCell subclass is through a storyboard. In Chapter 9, you saw that storyboards for table view controllers have a Prototype Cells section. This is where you will lay out the content for the ItemCell. Open and select the UITableViewCell in the document outline. Open its attributes inspector, change the Style to Custom, and change the .

TỪ KHÓA LIÊN QUAN