On certain conditions, if users intent to leave the current view (e.g. pop the current view, push other view, or select other tab items etc.), a UIAlertController should be presented to confirm users' real intention.
Users can press OK to proceed the view transitioning, or Cancel to stay on the current view.
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if someConditions {
promptUIAlert()
}
}
Any solutions that can achieve that requirements?
First of all, you cannot handle this is
viewWillDisappear
because at this point it has already been decided that the view will disappear. You need to handle this wherever you have view transitions (push, pop, present, dismiss).You have to handle the transitions in the confirmation alert action. You alert would look something like this.