Представьте ViewController, хотя UIAlertController находится в иерархии представлений
Я бы хотел presentViewController
когда alertController
представлена.
Я хочу, например, если пользователь нажимает кнопку ОК, я хочу показать ViewController
из AppDelegate на PushNotification.
Я узнал на ТАК, что UIAlertController
представлена в другой ветке, поэтому хочу представить ViewController
после того, как пользователь нажимает кнопку ОК и переходит к основному потоку, как показано ниже:
func presentRScreenFromRootViewController()
{
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let rViewController = storyboard.instantiateViewControllerWithIdentifier("rsh") as! R_SVC
dispatch_async(dispatch_get_main_queue(),{
self.window?.rootViewController?.presentViewController(rViewController, animated: true, completion: nil)
});
}
Но я получаю предупреждение как:
Attempt to present <BB.R_SVC: 0x15b983600> on <SWRevealViewController: 0x15652df00> which is already presenting <UIAlertController: 0x15b4f2dd0>
Это происходит потому, что viewcontroller представляет alertcontroller. В остальное время он работает хорошо. Мой rootViewController изменяется и переходит к следующему экрану. Но когда есть UIAlertController, я получаю предупреждение как попытку представить viewcontroller, которого нет в иерархии представлений.
Что я делаю неправильно?
1 ответ
При создании UIAlertController поместите код VCpresent в действие UIAlertAction следующим образом
let alert = UIAlertController(title: "your title", message "move to next VC?", preferredStyle: UIAlertController: UIAlertControllerStyle.Alert)
let action: UIAlertAction = UIAlertAction(title: "yes move to next VC", style: UIAlertActionStyle.Default) {action -> Void in
let rViewController = storyboard.instantiateViewControllerWithIdentifier("rsh") as! R_SVC
self.presentViewController(rViewController, animated: true, completion: nil) })
alert.addAction(defaultAction)
self.presentViewController(alert, animated: true, completion: nil)
редактировать: может быть, попробуйте закрыть все UIAlertControllers, представленные в настоящее время.