use TableView to show password detail

This commit is contained in:
Bob Sun 2017-02-02 21:04:31 +08:00
parent 35a9c84b63
commit 8f23f609a7
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
8 changed files with 156 additions and 60 deletions

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