From a3cbed9a2110cffb0542377b3a606227b35955cd Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Sat, 11 Feb 2017 16:08:41 +0800 Subject: [PATCH] add additional TextView in add password page --- pass.xcodeproj/project.pbxproj | 8 +++ .../AddPasswordTableViewController.swift | 36 +++++++----- pass/Views/TextViewTableViewCell.swift | 30 ++++++++++ pass/Views/TextViewTableViewCell.xib | 56 +++++++++++++++++++ 4 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 pass/Views/TextViewTableViewCell.swift create mode 100644 pass/Views/TextViewTableViewCell.xib diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index 23df6d0..b60ae6d 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ DC037CB81E4DD1A500609409 /* AddPasswordTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC037CB71E4DD1A500609409 /* AddPasswordTableViewController.swift */; }; DC037CBB1E4DD47B00609409 /* TextFieldTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC037CB91E4DD47B00609409 /* TextFieldTableViewCell.swift */; }; DC037CBC1E4DD47B00609409 /* TextFieldTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DC037CBA1E4DD47B00609409 /* TextFieldTableViewCell.xib */; }; + DC037CBF1E4ED4E100609409 /* TextViewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC037CBD1E4ED4E100609409 /* TextViewTableViewCell.swift */; }; + DC037CC01E4ED4E100609409 /* TextViewTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DC037CBE1E4ED4E100609409 /* TextViewTableViewCell.xib */; }; DC1208581E35EBE60042942E /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC1208571E35EBE60042942E /* ObjectiveGit.framework */; }; DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */; }; DC193FFC1E49E0340077E0A3 /* PasscodeLock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC193FFB1E49E0340077E0A3 /* PasscodeLock.framework */; }; @@ -64,6 +66,8 @@ DC037CB71E4DD1A500609409 /* AddPasswordTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddPasswordTableViewController.swift; sourceTree = ""; }; DC037CB91E4DD47B00609409 /* TextFieldTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldTableViewCell.swift; sourceTree = ""; }; DC037CBA1E4DD47B00609409 /* TextFieldTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TextFieldTableViewCell.xib; sourceTree = ""; }; + DC037CBD1E4ED4E100609409 /* TextViewTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextViewTableViewCell.swift; sourceTree = ""; }; + DC037CBE1E4ED4E100609409 /* TextViewTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TextViewTableViewCell.xib; sourceTree = ""; }; DC1208571E35EBE60042942E /* ObjectiveGit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectiveGit.framework; path = Carthage/Build/iOS/ObjectiveGit.framework; sourceTree = ""; }; DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsTableViewController.swift; sourceTree = ""; }; DC193FFB1E49E0340077E0A3 /* PasscodeLock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PasscodeLock.framework; path = Carthage/Build/iOS/PasscodeLock.framework; sourceTree = ""; }; @@ -180,6 +184,8 @@ DC037CBA1E4DD47B00609409 /* TextFieldTableViewCell.xib */, DCDDEAB11E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift */, DCDDEAB21E4896BF00F68193 /* PasswordDetailTitleTableViewCell.xib */, + DC037CBD1E4ED4E100609409 /* TextViewTableViewCell.swift */, + DC037CBE1E4ED4E100609409 /* TextViewTableViewCell.xib */, ); path = Views; sourceTree = ""; @@ -303,6 +309,7 @@ DCDDEAB41E4896BF00F68193 /* PasswordDetailTitleTableViewCell.xib in Resources */, DCDDEAB01E4639F300F68193 /* LabelTableViewCell.xib in Resources */, DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */, + DC037CC01E4ED4E100609409 /* TextViewTableViewCell.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -381,6 +388,7 @@ buildActionMask = 2147483647; files = ( DCC408A41E2FCC9E00F29B0E /* PasswordStore.swift in Sources */, + DC037CBF1E4ED4E100609409 /* TextViewTableViewCell.swift in Sources */, DC8963C01E38EEB900828B09 /* SSHKeySettingTableViewController.swift in Sources */, DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */, DCA0499C1E3362F400522E8F /* PGPKeySettingTableViewController.swift in Sources */, diff --git a/pass/Controllers/AddPasswordTableViewController.swift b/pass/Controllers/AddPasswordTableViewController.swift index e3a2998..424f5e1 100644 --- a/pass/Controllers/AddPasswordTableViewController.swift +++ b/pass/Controllers/AddPasswordTableViewController.swift @@ -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)) } diff --git a/pass/Views/TextViewTableViewCell.swift b/pass/Views/TextViewTableViewCell.swift new file mode 100644 index 0000000..88914d2 --- /dev/null +++ b/pass/Views/TextViewTableViewCell.swift @@ -0,0 +1,30 @@ +// +// TextViewTableViewCell.swift +// pass +// +// Created by Mingshen Sun on 11/2/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit + +class TextViewTableViewCell: UITableViewCell { + + @IBOutlet weak var contentTextView: UITextView! + @IBOutlet weak var titleLabel: UILabel! + override func awakeFromNib() { + super.awakeFromNib() + titleLabel.isUserInteractionEnabled = true + let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tap(_:))) + titleLabel.addGestureRecognizer(tapGestureRecognizer) + } + + func tap(_ sender: Any?) { + contentTextView.becomeFirstResponder() + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + } + +} diff --git a/pass/Views/TextViewTableViewCell.xib b/pass/Views/TextViewTableViewCell.xib new file mode 100644 index 0000000..b06cf8a --- /dev/null +++ b/pass/Views/TextViewTableViewCell.xib @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. + + + + + + + + + + + + + + + + + + + + + +