refactor LabelTableView(Cell)

This commit is contained in:
Bob Sun 2017-02-05 13:56:37 +08:00
parent 67570256d0
commit 63a0ad8fe6
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
2 changed files with 18 additions and 2 deletions

View file

@ -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 {

View file

@ -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
}