add additional TextView in add password page

This commit is contained in:
Bob Sun 2017-02-11 16:08:41 +08:00
parent 49b26f0276
commit a3cbed9a21
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
4 changed files with 115 additions and 15 deletions

View file

@ -9,14 +9,16 @@
import UIKit
class AddPasswordTableViewController: UITableViewController {
let tableTitles = ["name", "password"]
let tableTitles = ["name", "password", "additions"]
var password: Password?
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "TextFieldTableViewCell", bundle: nil), forCellReuseIdentifier: "textFieldCell")
tableView.register(UINib(nibName: "TextViewTableViewCell", bundle: nil), forCellReuseIdentifier: "textViewCell")
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 52
tableView.estimatedRowHeight = 64
tableView.allowsSelection = false
}
@ -25,26 +27,30 @@ class AddPasswordTableViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "textFieldCell", for: indexPath) as! TextFieldTableViewCell
cell.titleLabel.text = tableTitles[indexPath.row]
return cell
if tableTitles[indexPath.row] == "additions" {
let cell = tableView.dequeueReusableCell(withIdentifier: "textViewCell", for: indexPath) as! TextViewTableViewCell
cell.titleLabel.text = tableTitles[indexPath.row]
cell.contentTextView.text = ""
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "textFieldCell", for: indexPath) as! TextFieldTableViewCell
cell.titleLabel.text = tableTitles[indexPath.row]
return cell
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let name = getCellForName(name: "name")!.contentTextField.text ?? ""
let passwordText = getCellForName(name: "password")!.contentTextField.text ?? ""
// let additions = getCellForName(name: "additions")!.contentTextField.text ?? ""
// let additionSplit = additions.characters.split(separator: ":").map(String.init)
// print(additionSplit)
// let additionField = AdditionField(title: additionSplit[0], content: additionSplit[1])
password = Password(name: name, username: "", password: passwordText, additions: [])
let nameCell = getCellForName(name: "name")! as! TextFieldTableViewCell
let passwordCell = getCellForName(name: "password")! as! TextFieldTableViewCell
let additionsCell = getCellForName(name: "additions")! as! TextViewTableViewCell
password = Password(name: nameCell.contentTextField.text!, plainText: "\(passwordCell.contentTextField.text!)\n\(additionsCell.contentTextView.text!)")
}
func getCellAt(row: Int) -> TextFieldTableViewCell? {
return tableView.cellForRow(at: IndexPath(row: row, section: 0)) as? TextFieldTableViewCell
func getCellAt(row: Int) -> UITableViewCell? {
return tableView.cellForRow(at: IndexPath(row: row, section: 0))
}
func getCellForName(name: String) -> TextFieldTableViewCell? {
func getCellForName(name: String) -> UITableViewCell? {
let index = tableTitles.index(of: name)!
return getCellAt(row: Int(index))
}