From fc3701abfc62818723d4859c58dc16eacc26eb0f Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Thu, 9 Feb 2017 22:13:07 +0800 Subject: [PATCH] add a new cell type .detail --- .../BasicStaticTableViewController.swift | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/pass/Controllers/BasicStaticTableViewController.swift b/pass/Controllers/BasicStaticTableViewController.swift index 7390000..49ee6ed 100644 --- a/pass/Controllers/BasicStaticTableViewController.swift +++ b/pass/Controllers/BasicStaticTableViewController.swift @@ -12,11 +12,11 @@ import MessageUI enum CellDataType { - case link, segue, empty + case link, segue, empty, detail } enum CellDataKey { - case type, title, link, accessoryType, detailDisclosureAction, detailDisclosureData + case type, title, link, accessoryType, detailDisclosureAction, detailDisclosureData, detailText } class BasicStaticTableViewController: UITableViewController, MFMailComposeViewControllerDelegate { @@ -42,15 +42,26 @@ class BasicStaticTableViewController: UITableViewController, MFMailComposeViewCo } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = UITableViewCell() + let cellData = tableData[indexPath.section][indexPath.row] - cell.textLabel?.text = cellData[CellDataKey.title] as? String - if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType { - cell.accessoryType = accessoryType - } else { - cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator + let cellDataType = cellData[CellDataKey.type] as? CellDataType + var cell: UITableViewCell? + switch cellDataType! { + case .detail: + cell = UITableViewCell(style: .value1, reuseIdentifier: "value1 cell") + cell?.accessoryType = .none + cell?.detailTextLabel?.text = cellData[CellDataKey.detailText] as? String + default: + cell = UITableViewCell(style: .default, reuseIdentifier: "default cell") + cell?.textLabel?.text = cellData[CellDataKey.title] as? String + if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType { + cell?.accessoryType = accessoryType + } else { + cell?.accessoryType = .disclosureIndicator + } } - return cell + cell?.textLabel?.text = cellData[CellDataKey.title] as? String + return cell ?? UITableViewCell() } override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {