Exposing the Properties of ItemCell

For ItemsViewController to configure the content of an ItemCell in tableView(_:cellForRowAt:), the cell must have properties that expose the three labels. These properties will be set through outlet connections in Main.storyboard.

The next step, then, is to create and connect outlets on ItemCell for each of its subviews.

Open ItemCell.swift and add three properties for the outlets.

Listing 10.2  Adding outlets to ItemCell (ItemCell.swift)

import UIKit

class ItemCell: UITableViewCell {

    @IBOutlet var nameLabel: UILabel!
    @IBOutlet var serialNumberLabel: UILabel!
    @IBOutlet var valueLabel: UILabel!

}

You are going to connect the outlets for the three views to the ItemCell. When connecting outlets earlier in the book, you Control-dragged from the view controller in the storyboard to the appropriate view. But the outlets for ItemCell are not outlets on a controller. They are outlets on a view: the custom UITableViewCell subclass.

Therefore, to connect the outlets for ItemCell, you will connect them to the ItemCell view itself.

Open Main.storyboard. Control-click the ItemCell in the document outline and make the three outlet connections shown in Figure 10.5.

Figure 10.5  Connecting the outlets

Connecting the outlets
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset