use TableView to show password detail
This commit is contained in:
parent
35a9c84b63
commit
8f23f609a7
8 changed files with 156 additions and 60 deletions
|
|
@ -36,7 +36,7 @@
|
|||
</subviews>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<segue destination="Jts-IV-D1A" kind="show" identifier="showPasswordDetail" id="i0a-rZ-Bqd"/>
|
||||
<segue destination="tW4-E9-CGv" kind="show" identifier="showPasswordDetail" id="OrR-Ve-XMm"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
|
|
@ -497,39 +497,22 @@
|
|||
</objects>
|
||||
<point key="canvasLocation" x="4414" y="3286"/>
|
||||
</scene>
|
||||
<!--Password Detail View Controller-->
|
||||
<scene sceneID="9b5-fu-vx9">
|
||||
<!--Password Detail Table View Controller-->
|
||||
<scene sceneID="9wY-d0-fB1">
|
||||
<objects>
|
||||
<viewController id="Jts-IV-D1A" customClass="PasswordDetailViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Vhp-eB-nlX"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="AwD-QU-ZDy"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="aAM-Iy-xPP">
|
||||
<tableViewController id="tW4-E9-CGv" customClass="PasswordDetailTableViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="hfi-6O-04U">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="kMN-7r-0CD">
|
||||
<rect key="frame" x="16" y="0.0" width="359" height="667"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<string 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.</string>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
|
||||
</textView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="kMN-7r-0CD" firstAttribute="leading" secondItem="aAM-Iy-xPP" secondAttribute="leadingMargin" id="Kd2-e2-ou5"/>
|
||||
<constraint firstItem="kMN-7r-0CD" firstAttribute="top" secondItem="aAM-Iy-xPP" secondAttribute="top" id="UYu-K1-orN"/>
|
||||
<constraint firstAttribute="bottom" secondItem="kMN-7r-0CD" secondAttribute="bottom" id="XBs-6b-j50"/>
|
||||
<constraint firstAttribute="trailing" secondItem="kMN-7r-0CD" secondAttribute="trailing" id="u1d-Of-tmc"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="passwordTextView" destination="kMN-7r-0CD" id="nSW-kn-X8u"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="ek1-Cw-dZH" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
|
||||
<sections/>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="tW4-E9-CGv" id="5QL-0S-PR1"/>
|
||||
<outlet property="delegate" destination="tW4-E9-CGv" id="7PQ-0M-SCC"/>
|
||||
</connections>
|
||||
</tableView>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="9sC-44-OKL" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="3430" y="993"/>
|
||||
</scene>
|
||||
|
|
|
|||
24
pass/LabelTableViewCell.swift
Normal file
24
pass/LabelTableViewCell.swift
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// LabelTableViewCell.swift
|
||||
// pass
|
||||
//
|
||||
// Created by Mingshen Sun on 2/2/2017.
|
||||
// Copyright © 2017 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class LabelTableViewCell: UITableViewCell {
|
||||
|
||||
@IBOutlet weak var contentLabel: UILabel!
|
||||
@IBOutlet weak var titleLabel: UILabel!
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
}
|
||||
|
||||
override func setSelected(_ selected: Bool, animated: Bool) {
|
||||
super.setSelected(selected, animated: animated)
|
||||
}
|
||||
|
||||
}
|
||||
51
pass/LabelTableViewCell.xib
Normal file
51
pass/LabelTableViewCell.xib
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?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" reuseIdentifier="labelCell" id="KGk-i7-Jjw" customClass="LabelTableViewCell" customModule="pass" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="333" height="52"/>
|
||||
<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="333" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="content" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yyr-cF-QN0">
|
||||
<rect key="frame" x="15" y="23" width="310" height="21"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Dqz-7n-uEZ">
|
||||
<rect key="frame" x="15" y="8" width="310" height="15"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
|
||||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="Dqz-7n-uEZ" secondAttribute="trailing" id="228-VM-Z8Y"/>
|
||||
<constraint firstItem="Dqz-7n-uEZ" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="7" id="CVm-uc-iVo"/>
|
||||
<constraint firstAttribute="topMargin" secondItem="Dqz-7n-uEZ" secondAttribute="top" id="N4y-iT-CiY"/>
|
||||
<constraint firstItem="yyr-cF-QN0" firstAttribute="leading" secondItem="Dqz-7n-uEZ" secondAttribute="leading" id="TpW-bu-QIx"/>
|
||||
<constraint firstItem="yyr-cF-QN0" firstAttribute="width" secondItem="Dqz-7n-uEZ" secondAttribute="width" id="ZXa-fK-0Bg"/>
|
||||
<constraint firstItem="yyr-cF-QN0" firstAttribute="top" secondItem="Dqz-7n-uEZ" secondAttribute="bottom" id="sgc-hN-i8t"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<outlet property="contentLabel" destination="yyr-cF-QN0" id="lhr-oA-ofC"/>
|
||||
<outlet property="titleLabel" destination="Dqz-7n-uEZ" id="Hac-od-A7K"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="27.5" y="58"/>
|
||||
</tableViewCell>
|
||||
</objects>
|
||||
</document>
|
||||
|
|
@ -12,9 +12,9 @@ import SwiftyUserDefaults
|
|||
class Password {
|
||||
var name = ""
|
||||
var password = ""
|
||||
var additions: [String: String]?
|
||||
var additions: [String: String]
|
||||
|
||||
init(name: String, password: String, additions: [String: String]?) {
|
||||
init(name: String, password: String, additions: [String: String]) {
|
||||
self.name = name
|
||||
self.password = password
|
||||
self.additions = additions
|
||||
|
|
|
|||
52
pass/PasswordDetailTableViewController.swift
Normal file
52
pass/PasswordDetailTableViewController.swift
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// PasswordDetailTableViewController.swift
|
||||
// pass
|
||||
//
|
||||
// Created by Mingshen Sun on 2/2/2017.
|
||||
// Copyright © 2017 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class PasswordDetailTableViewController: UITableViewController {
|
||||
var passwordEntity: PasswordEntity?
|
||||
|
||||
struct FormCell {
|
||||
var title: String
|
||||
var content: String
|
||||
}
|
||||
|
||||
var formData = [[FormCell]]()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell")
|
||||
let password = passwordEntity!.decrypt()!
|
||||
formData.append([])
|
||||
if let username = password.additions["Username"] {
|
||||
formData[0].append(FormCell(title: "username", content: username))
|
||||
}
|
||||
formData[0].append(FormCell(title: "password", content: password.password))
|
||||
}
|
||||
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return formData.count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return formData[section].count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell", for: indexPath) as! LabelTableViewCell
|
||||
cell.titleLabel.text = formData[indexPath.section][indexPath.row].title
|
||||
cell.contentLabel.text = formData[indexPath.section][indexPath.row].content
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||
return 52
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
//
|
||||
// PasswordDetailViewController.swift
|
||||
// pass
|
||||
//
|
||||
// Created by Mingshen Sun on 18/1/2017.
|
||||
// Copyright © 2017 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import SwiftyUserDefaults
|
||||
|
||||
class PasswordDetailViewController: UIViewController {
|
||||
|
||||
@IBOutlet weak var passwordTextView: UITextView!
|
||||
var passwordEntity: PasswordEntity?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
let password = passwordEntity!.decrypt()!
|
||||
passwordTextView.text = password.password
|
||||
}
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ class PasswordsTableViewController: UITableViewController {
|
|||
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||
if segue.identifier == "showPasswordDetail" {
|
||||
if let viewController = segue.destination as? PasswordDetailViewController {
|
||||
if let viewController = segue.destination as? PasswordDetailTableViewController {
|
||||
let selectedIndexPath = self.tableView.indexPath(for: sender as! UITableViewCell)!
|
||||
let index = sections[selectedIndexPath.section].index + selectedIndexPath.row
|
||||
let password: PasswordEntity
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue