2017-02-13 01:15:42 +08:00
|
|
|
//
|
|
|
|
|
// PasswordEditorTableViewController.swift
|
|
|
|
|
// pass
|
|
|
|
|
//
|
|
|
|
|
// Created by Mingshen Sun on 12/2/2017.
|
|
|
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
enum PasswordEditorCellType {
|
|
|
|
|
case textFieldCell, textViewCell, fillPasswordCell
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum PasswordEditorCellKey {
|
|
|
|
|
case type, title, content, placeholders
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PasswordEditorTableViewController: UITableViewController {
|
|
|
|
|
var navigationItemTitle: String?
|
|
|
|
|
var tableData = [
|
|
|
|
|
[Dictionary<PasswordEditorCellKey, Any>]
|
|
|
|
|
]()
|
|
|
|
|
var sectionHeaderTitles = [String]()
|
2017-02-21 01:06:03 +08:00
|
|
|
var sectionFooterTitles = [String]()
|
2017-02-13 01:15:42 +08:00
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
navigationItem.title = navigationItemTitle
|
|
|
|
|
tableView.register(UINib(nibName: "TextFieldTableViewCell", bundle: nil), forCellReuseIdentifier: "textFieldCell")
|
|
|
|
|
tableView.register(UINib(nibName: "TextViewTableViewCell", bundle: nil), forCellReuseIdentifier: "textViewCell")
|
|
|
|
|
tableView.register(UINib(nibName: "FillPasswordTableViewCell", bundle: nil), forCellReuseIdentifier: "fillPasswordCell")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tableView.rowHeight = UITableViewAutomaticDimension
|
|
|
|
|
tableView.estimatedRowHeight = 48
|
|
|
|
|
tableView.allowsSelection = false
|
2017-02-21 01:06:03 +08:00
|
|
|
self.tableView.sectionFooterHeight = UITableViewAutomaticDimension;
|
|
|
|
|
self.tableView.estimatedSectionFooterHeight = 0;
|
2017-02-13 01:15:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
|
let cellData = tableData[indexPath.section][indexPath.row]
|
|
|
|
|
var cell = ContentTableViewCell()
|
|
|
|
|
|
|
|
|
|
switch cellData[PasswordEditorCellKey.type] as! PasswordEditorCellType {
|
|
|
|
|
case .textViewCell:
|
|
|
|
|
cell = tableView.dequeueReusableCell(withIdentifier: "textViewCell", for: indexPath) as! ContentTableViewCell
|
|
|
|
|
case .fillPasswordCell:
|
|
|
|
|
cell = tableView.dequeueReusableCell(withIdentifier: "fillPasswordCell", for: indexPath) as! ContentTableViewCell
|
|
|
|
|
default:
|
|
|
|
|
cell = tableView.dequeueReusableCell(withIdentifier: "textFieldCell", for: indexPath) as! ContentTableViewCell
|
|
|
|
|
}
|
|
|
|
|
if let content = cellData[PasswordEditorCellKey.content] as? String {
|
|
|
|
|
cell.setContent(content: content)
|
|
|
|
|
}
|
|
|
|
|
return cell
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
|
|
return 44
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
|
return tableData.count
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
|
return tableData[section].count
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
|
|
|
|
return sectionHeaderTitles[section]
|
|
|
|
|
}
|
2017-02-21 01:06:03 +08:00
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
|
|
|
|
return sectionFooterTitles[section]
|
|
|
|
|
}
|
2017-02-13 01:15:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|