Go back to the "password store" view if user discards all local changes.

- Otherwise, editing an updated entry will crash the app.
- Showing an deleted entry is not reasonable.
This commit is contained in:
Yishi Lin 2017-03-11 02:07:04 +08:00
parent 11066d0bb6
commit 5ea9a3118b

View file

@ -17,6 +17,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
var password: Password?
var passwordImage: UIImage?
var oneTimePasswordIndexPath : IndexPath?
var shouldPopCurrentView = false
let indicatorLable: UILabel = {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 21))
@ -118,6 +119,7 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
}
self.setupUpdateOneTimePassword()
self.addNotificationObservers()
}
@ -386,4 +388,22 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni
return true
}
private func addNotificationObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(setShouldPopCurrentView), name: NSNotification.Name(rawValue: "passwordStoreChangeDiscarded"), object: nil)
}
func setShouldPopCurrentView() {
self.shouldPopCurrentView = true
}
override func viewDidAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if self.shouldPopCurrentView {
let alert = UIAlertController(title: "Notice", message: "All previous local changes have been discarded. Your current Password Store will be shown.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {_ in
_ = self.navigationController?.popViewController(animated: true)
}))
self.present(alert, animated: true, completion: nil)
}
}
}