From fca0b5099092d13af0575ebd1d8116360d7ec2be Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Thu, 9 Feb 2017 11:12:14 +0800 Subject: [PATCH] support cell type: detailDesclosure --- .../BasicStaticTableViewController.swift | 14 ++++++++++++-- .../OpenSourceComponentsTableViewController.swift | 8 +++++++- pass/PasswordDetailTitleTableViewCell.xib | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pass/Controllers/BasicStaticTableViewController.swift b/pass/Controllers/BasicStaticTableViewController.swift index ac83bd3..85949d9 100644 --- a/pass/Controllers/BasicStaticTableViewController.swift +++ b/pass/Controllers/BasicStaticTableViewController.swift @@ -13,7 +13,7 @@ enum CellDataType { } enum CellDataKey { - case type, title, link, footer + case type, title, link, footer, accessoryType, detailDisclosureAction, detailDisclosureData } class BasicStaticTableViewController: UITableViewController { @@ -42,10 +42,20 @@ class BasicStaticTableViewController: UITableViewController { let cell = UITableViewCell() let cellData = tableData[indexPath.section][indexPath.row] cell.textLabel?.text = cellData[CellDataKey.title] as? String - cell.accessoryType = .disclosureIndicator + if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType { + cell.accessoryType = accessoryType + } else { + cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator + } return cell } + override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { + let cellData = tableData[indexPath.section][indexPath.row] + let selector = cellData[CellDataKey.detailDisclosureAction] as? Selector + perform(selector, with: cellData[CellDataKey.detailDisclosureData]) + } + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) let cellData = tableData[indexPath.section][indexPath.row] diff --git a/pass/Controllers/OpenSourceComponentsTableViewController.swift b/pass/Controllers/OpenSourceComponentsTableViewController.swift index 5a4a4ed..164914e 100644 --- a/pass/Controllers/OpenSourceComponentsTableViewController.swift +++ b/pass/Controllers/OpenSourceComponentsTableViewController.swift @@ -31,11 +31,17 @@ class OpenSourceComponentsTableViewController: BasicStaticTableViewController { tableData.append([]) for item in openSourceComponents { tableData[0].append( - [CellDataKey.type: CellDataType.link, CellDataKey.title: item[0], CellDataKey.link: item[1]] + [CellDataKey.type: CellDataType.link, CellDataKey.title: item[0], CellDataKey.link: item[1], CellDataKey.accessoryType: UITableViewCellAccessoryType.detailDisclosureButton, CellDataKey.detailDisclosureAction: #selector(actOnDetailDisclosureButton(_:)), CellDataKey.detailDisclosureData: item[2]] ) } navigationItemTitle = "Open Source Components" super.viewDidLoad() } + + func actOnDetailDisclosureButton(_ sender: Any?) { + if let link = sender as? String { + UIApplication.shared.open(URL(string: link)!, options: [:], completionHandler: nil) + } + } } diff --git a/pass/PasswordDetailTitleTableViewCell.xib b/pass/PasswordDetailTitleTableViewCell.xib index ff63b25..7467ad6 100644 --- a/pass/PasswordDetailTitleTableViewCell.xib +++ b/pass/PasswordDetailTitleTableViewCell.xib @@ -27,13 +27,13 @@