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

@ -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 = "<group>"; };
DC037CB91E4DD47B00609409 /* TextFieldTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldTableViewCell.swift; sourceTree = "<group>"; };
DC037CBA1E4DD47B00609409 /* TextFieldTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TextFieldTableViewCell.xib; sourceTree = "<group>"; };
DC037CBD1E4ED4E100609409 /* TextViewTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextViewTableViewCell.swift; sourceTree = "<group>"; };
DC037CBE1E4ED4E100609409 /* TextViewTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TextViewTableViewCell.xib; sourceTree = "<group>"; };
DC1208571E35EBE60042942E /* ObjectiveGit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjectiveGit.framework; path = Carthage/Build/iOS/ObjectiveGit.framework; sourceTree = "<group>"; };
DC193FF91E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsTableViewController.swift; sourceTree = "<group>"; };
DC193FFB1E49E0340077E0A3 /* PasscodeLock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PasscodeLock.framework; path = Carthage/Build/iOS/PasscodeLock.framework; sourceTree = "<group>"; };
@ -180,6 +184,8 @@
DC037CBA1E4DD47B00609409 /* TextFieldTableViewCell.xib */,
DCDDEAB11E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift */,
DCDDEAB21E4896BF00F68193 /* PasswordDetailTitleTableViewCell.xib */,
DC037CBD1E4ED4E100609409 /* TextViewTableViewCell.swift */,
DC037CBE1E4ED4E100609409 /* TextViewTableViewCell.xib */,
);
path = Views;
sourceTree = "<group>";
@ -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 */,

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))
}

View file

@ -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)
}
}

View file

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="145" id="KGk-i7-Jjw" customClass="TextViewTableViewCell" customModule="pass" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="145"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="144.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" text="title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Tvq-BT-MKW">
<rect key="frame" x="15" y="8" width="297" height="14.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
<color key="textColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="xHX-Sh-1pR">
<rect key="frame" x="15" y="25.5" width="297" height="111"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="100" id="OY2-uq-PPw"/>
</constraints>
<mutableString key="text">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.</mutableString>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences" autocorrectionType="no"/>
</textView>
</subviews>
<constraints>
<constraint firstItem="xHX-Sh-1pR" firstAttribute="top" secondItem="Tvq-BT-MKW" secondAttribute="bottom" constant="3" id="EAF-pS-6NK"/>
<constraint firstItem="Tvq-BT-MKW" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" id="Iff-UZ-E7V"/>
<constraint firstAttribute="trailingMargin" secondItem="Tvq-BT-MKW" secondAttribute="trailing" id="Iqw-GY-KZN"/>
<constraint firstAttribute="bottomMargin" secondItem="xHX-Sh-1pR" secondAttribute="bottom" id="UPQ-jk-QJR"/>
<constraint firstItem="xHX-Sh-1pR" firstAttribute="trailing" secondItem="Tvq-BT-MKW" secondAttribute="trailing" id="bwz-g9-8Xw"/>
<constraint firstItem="xHX-Sh-1pR" firstAttribute="leading" secondItem="Tvq-BT-MKW" secondAttribute="leading" id="oos-pf-UiI"/>
<constraint firstItem="Tvq-BT-MKW" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="7" id="z09-yX-Rdj"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="contentTextView" destination="xHX-Sh-1pR" id="grB-ki-nyo"/>
<outlet property="titleLabel" destination="Tvq-BT-MKW" id="WCK-LR-2Y0"/>
</connections>
<point key="canvasLocation" x="34" y="66.5"/>
</tableViewCell>
</objects>
</document>