У меня есть UITabBar
с 5 вкладками. Когда выбрана средняя вкладка, я хочу, чтобы всплыл лист действий UIAlertController
, дождался действий пользователя и затем загрузил новый вид, как только пользователь выбрал лист, так как мне нужны данные с листа для корректной загрузки вида.
У меня сейчас есть этот код:
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
}
}
Это работает во всех отношениях, за исключением того, что новый вид загружается до того, как пользователь выберет что-либо из листа действий. Можно ли заставить UITabBar
ждать действия или мне нужно по-другому это сделать?