add a new cell type .detail

This commit is contained in:
Bob Sun 2017-02-09 22:13:07 +08:00
parent cbfb3d61b0
commit fc3701abfc
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4

View file

@ -12,11 +12,11 @@ import MessageUI
enum CellDataType { enum CellDataType {
case link, segue, empty case link, segue, empty, detail
} }
enum CellDataKey { enum CellDataKey {
case type, title, link, accessoryType, detailDisclosureAction, detailDisclosureData case type, title, link, accessoryType, detailDisclosureAction, detailDisclosureData, detailText
} }
class BasicStaticTableViewController: UITableViewController, MFMailComposeViewControllerDelegate { class BasicStaticTableViewController: UITableViewController, MFMailComposeViewControllerDelegate {
@ -42,15 +42,26 @@ class BasicStaticTableViewController: UITableViewController, MFMailComposeViewCo
} }
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let cellData = tableData[indexPath.section][indexPath.row] let cellData = tableData[indexPath.section][indexPath.row]
cell.textLabel?.text = cellData[CellDataKey.title] as? String 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 { if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType {
cell.accessoryType = accessoryType cell?.accessoryType = accessoryType
} else { } else {
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator cell?.accessoryType = .disclosureIndicator
} }
return cell }
cell?.textLabel?.text = cellData[CellDataKey.title] as? String
return cell ?? UITableViewCell()
} }
override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {