48 lines
1.7 KiB
Swift
48 lines
1.7 KiB
Swift
//
|
|
// PasswordTableViewController.swift
|
|
// pass
|
|
//
|
|
// Created by Mingshen Sun on 18/1/2017.
|
|
// Copyright © 2017 Bob Sun. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import SwiftGit2
|
|
import Result
|
|
import SVProgressHUD
|
|
|
|
class PasswordTableViewController: UITableViewController {
|
|
private var passwordEntities: [PasswordEntity]?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
|
NotificationCenter.default.addObserver(self, selector: #selector(PasswordTableViewController.actOnPasswordUpdatedNotification), name: NSNotification.Name(rawValue: "passwordUpdated"), object: nil)
|
|
}
|
|
|
|
func actOnPasswordUpdatedNotification() {
|
|
passwordEntities = PasswordStore.shared.fetchPasswordEntityCoreData()
|
|
self.tableView.reloadData()
|
|
print("actOnPasswordUpdatedNotification")
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return passwordEntities!.count
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "passwordTableViewCell", for: indexPath)
|
|
cell.textLabel?.text = passwordEntities![indexPath.row].name
|
|
return cell
|
|
}
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
if segue.identifier == "showPasswordDetail" {
|
|
if let viewController = segue.destination as? PasswordDetailViewController {
|
|
let selectedRow = tableView.indexPathForSelectedRow!.row
|
|
viewController.passwordEntity = passwordEntities![selectedRow]
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|