I'm trying to remind user to save changes on current View Controller
let's say, i've got something like this:
here, inside TabBarController, and inside Navigation Controller I've got a "Favorites" tab. I want to display an alert, if user switches to "Contacts"
The issue is that Alert is shown over destination ViewController (Contacts), so it looks very weird for user.
Tested solutions:
first, i tried to use
override func viewWillDisappear(animated: Bool) {
self.leavingAlert()
}
//inside FavoritesViewController
next, I tried:
class FavoritesViewController: UIViewController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBarController?.delegate = self
}
func leavingAlert(){
let alert = UIAlertController(title: "Alert", message: "You forgot to do something here", preferredStyle: UIAlertControllerStyle.Alert)
let alertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
alert.addAction(alertAction)
self.presentViewController(alert, animated: true, completion: nil)
}
func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
self.leavingAlert()
}
}
Same effect
Then, i tried to reach the event through the TabBarViewController:
class TabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
if let navigationController = selectedViewController as? UINavigationController {
if let activeController = navigationController.visibleViewController as? FavoritesViewController {
activeController.leavingAlert()
}
}
}
}
And one more time - same effect.
Note, that I'm not going to interrupt this UITabBarController Segue. The idea is only to ask "Save or not to save?", and if "save", then do some stuff and continue switching tab, if "don't save" - switch the tab immediately.
Thank you for any help. If there is a solution in Obj-C, please also answer, i'll try to catch the idea.