show cancel if skills dirty

This commit is contained in:
nixzhu
2015-07-24 16:53:35 +08:00
parent 7fba0ad1e8
commit fa4dfcbf42
2 changed files with 74 additions and 13 deletions
@@ -18,7 +18,6 @@ class YepNavigationController: UINavigationController, UIGestureRecognizerDelega
delegate = self
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
@@ -77,14 +76,52 @@ class YepNavigationController: UINavigationController, UIGestureRecognizerDelega
return true
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
// http://stackoverflow.com/questions/20327165/popviewcontroller-strange-behaviour
// work
//// MARK: UINavigationBarDelegate
//
//extension UINavigationController {
//
//// func navigationBar(navigationBar: UINavigationBar, shouldPopItem item: UINavigationItem) -> Bool {
//// return true
//// }
//}
//
//extension YepNavigationController: UINavigationBarDelegate {
//
// //override
// func navigationBar(navigationBar: UINavigationBar, shouldPopItem item: UINavigationItem) -> Bool {
//
// let forcePop: () -> Void = {
// self.dirtyAction = nil
// self.forcePopAction?()
// self.forcePopAction = nil
// }
//
// if let dirtyAction = dirtyAction {
//
// YepAlert.confirmOrCancel(title: NSLocalizedString("Notice", comment: ""), message: NSLocalizedString("Save before pop?", comment: ""), confirmTitle: NSLocalizedString("OK", comment: ""), cancelTitle: NSLocalizedString("Cancel", comment: ""), inViewController: self.topViewController, withConfirmAction: {
//
// dirtyAction()
//
// forcePop()
//
// }, cancelAction: {
// forcePop()
// })
//
// return false
// }
//
// return true
// //return super.navigationBar(navigationBar, shouldPopItem: item)
// }
//
// func navigationBar(navigationBar: UINavigationBar, didPopItem item: UINavigationItem) {
//// self.forcePopAction?()
//// self.forcePopAction = nil
// self.popViewControllerAnimated(true)
// }
//}
@@ -11,6 +11,17 @@ import UIKit
class RegisterPickSkillsViewController: BaseViewController {
var isRegister = true
var isDirty = false {
didSet {
if !isRegister {
let backBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "cancel")
navigationItem.leftBarButtonItem = backBarButtonItem
}
navigationItem.rightBarButtonItem?.enabled = true
}
}
var afterChangeSkillsAction: ((masterSkills: [Skill], learningSkills: [Skill]) -> Void)?
@IBOutlet weak var skillsCollectionView: UICollectionView!
@@ -39,8 +50,9 @@ class RegisterPickSkillsViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
let doneBarButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "saveSkills:")
navigationItem.rightBarButtonItem = doneBarButton
let doneBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "saveSkills:")
navigationItem.rightBarButtonItem = doneBarButtonItem
navigationItem.rightBarButtonItem?.enabled = false
if !isRegister {
navigationItem.titleView = NavigationTitleLabel(title: NSLocalizedString("Change Skills", comment: ""))
@@ -70,7 +82,15 @@ class RegisterPickSkillsViewController: BaseViewController {
}
}
func cancel() {
navigationController?.popViewControllerAnimated(true)
}
@IBAction func saveSkills(sender: AnyObject) {
doSaveSkills()
}
func doSaveSkills() {
YepHUD.showActivityIndicator()
@@ -236,6 +256,10 @@ class RegisterPickSkillsViewController: BaseViewController {
self.updateSkillsCollectionView()
if !self.isDirty {
self.isDirty = success
}
return success
}
}