From 63a0ad8fe6be8eac86175c9b22eaaa961b7fa98c Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Sun, 5 Feb 2017 13:56:37 +0800 Subject: [PATCH] refactor LabelTableView(Cell) --- pass/LabelTableViewCell.swift | 14 ++++++++++++++ pass/PasswordDetailTableViewController.swift | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pass/LabelTableViewCell.swift b/pass/LabelTableViewCell.swift index 4dee5e9..fa85d20 100644 --- a/pass/LabelTableViewCell.swift +++ b/pass/LabelTableViewCell.swift @@ -8,10 +8,24 @@ import UIKit + +struct LabelTableViewCellData { + var title: String + var content: String +} + class LabelTableViewCell: UITableViewCell { @IBOutlet weak var contentLabel: UILabel! @IBOutlet weak var titleLabel: UILabel! + + + var cellData: LabelTableViewCellData? { + didSet { + titleLabel.text = cellData?.title + contentLabel.text = cellData?.content + } + } override var canBecomeFirstResponder: Bool { get { diff --git a/pass/PasswordDetailTableViewController.swift b/pass/PasswordDetailTableViewController.swift index 7c55903..c2c5753 100644 --- a/pass/PasswordDetailTableViewController.swift +++ b/pass/PasswordDetailTableViewController.swift @@ -75,8 +75,10 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell", for: indexPath) as! LabelTableViewCell - cell.titleLabel.text = tableData[indexPath.section].item[indexPath.row].title - cell.contentLabel.text = tableData[indexPath.section].item[indexPath.row].content + + let titleData = tableData[indexPath.section].item[indexPath.row].title + let contentData = tableData[indexPath.section].item[indexPath.row].content + cell.cellData = LabelTableViewCellData(title: titleData, content: contentData) return cell }