support cell type: detailDesclosure

This commit is contained in:
Bob Sun 2017-02-09 11:12:14 +08:00
parent 6411645568
commit fca0b50990
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
3 changed files with 21 additions and 5 deletions

View file

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