Ios 为什么';在presentviewcontroller处于警报状态后popviewcontroller是否工作?
在这段代码中,我创建了一个警报,并在警报之后直接使用popToRootViewControllerAnimated方法。由于某些原因,这不起作用,我发现的解决方法是在presentViewController的完成过程中调用该方法Ios 为什么';在presentviewcontroller处于警报状态后popviewcontroller是否工作?,ios,swift,Ios,Swift,在这段代码中,我创建了一个警报,并在警报之后直接使用popToRootViewControllerAnimated方法。由于某些原因,这不起作用,我发现的解决方法是在presentViewController的完成过程中调用该方法 为什么pop方法在presentViewController方法之后不起作用,除非将其放入闭包中?当您调用self.presentViewController(警报,动画:true,完成:nil)时,viewController将执行演示。并且,在进展过程中,不允许您
为什么pop方法在presentViewController方法之后不起作用,除非将其放入闭包中?当您调用
self.presentViewController(警报,动画:true,完成:nil)
时,viewController将执行演示。并且,在进展过程中,不允许您执行任何其他过渡/演示
实际上,在我的机器上运行代码时,我得到了以下日志:
popToViewController:transition:在发生现有转换或演示时调用;导航堆栈将不会更新
这应该解释得很清楚。您应该移动此行
self.navigationController!。popToRootViewControllerAnimated(true)
改为进入完成闭包。我认为只有在用户点击OK后,您才想使用popToRoot
,在这种情况下:
//Event created alert
let alert = UIAlertController(title: "Event Created", message: "Event successfully created", preferredStyle: UIAlertControllerStyle.Alert);
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:nil));
self.presentViewController(alert, animated: true, completion: nil);
//Pop back to table
self.navigationController!.popToRootViewControllerAnimated(true);
注:
- 您实际上不需要使用
代码>在swift中李>
// Created the alert
let alert = UIAlertController(title: "Event Created", message: "Event successfully created", preferredStyle: UIAlertControllerStyle.Alert)
// Create the action
let OKAction = UIAlertAction(title: "OK", style: .Default) { (action: UIAlertAction!) -> Void in
self.navigationController!.popToRootViewControllerAnimated(true);
}
// Add the action
alert.addAction(OKAction)
// Present the alert
self.presentViewController(alert, animated: true, completion: nil)