I have a UITabBar
with 5 tabs. When the middle tab is selected I want a UIAlertController
Action Sheet to pop up, await user action and then load the new view once the user has selected from the Sheet since I need the data from the Sheet to load the view correctly.
I currently have this code:
extension CustomTabBarController: UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
guard let index = viewControllers?.index(of: viewController) else {
return false
}
if index == 2 {
var choice = CreateChoice()
let alert = UIAlertController(title: "Select Creation Type", message: "Please select the desired creation type", preferredStyle: .actionSheet)
let action1 = UIAlertAction(title: "Quick Create", style: .default) { (action:UIAlertAction) in
choice.choice = "quick"
}
let action2 = UIAlertAction(title: "Cancel", style: .cancel) { (action:UIAlertAction) in
choice.choice = "cancel"
}
let action3 = UIAlertAction(title: "Full Create", style: .default) { (action:UIAlertAction) in
choice.choice = "full"
}
alert.addAction(action1)
alert.addAction(action2)
alert.addAction(action3)
present(alert, animated: true, completion: nil)
print(choice.choice)
if choice.choice == "cancel" {
return false
}
return true
}
return true
}
}
This works in every way except the new view loads before the user selects anything from the Action Sheet. Is it possible to make the UITabBar
wait for the action or do I need to go about this another way?