Ios “当”时如何关闭显示视图控制器;“好的”;在UIAlertController中点击操作
我试图在UIAlertAction的完成处理程序中关闭当前视图控制器,但它没有关闭。我编写了以下代码(加载指示器只是一个加载警报控制器,当数据成功上载时,我会将其关闭):Ios “当”时如何关闭显示视图控制器;“好的”;在UIAlertController中点击操作,ios,swift,uialertcontroller,dismiss,uialertaction,Ios,Swift,Uialertcontroller,Dismiss,Uialertaction,我试图在UIAlertAction的完成处理程序中关闭当前视图控制器,但它没有关闭。我编写了以下代码(加载指示器只是一个加载警报控制器,当数据成功上载时,我会将其关闭): 但是,在单击警报中的“确定”后,会打印“确定已选择”,但不会解除视图控制器。调试器中没有显示任何其他内容。尝试在主线程上取消它,并检查是否在导航层次结构中显示或推送ViewController loadingIndicator.dismiss(animated: true) { let success = UIAler
但是,在单击警报中的“确定”后,会打印“确定已选择”,但不会解除视图控制器。调试器中没有显示任何其他内容。尝试在主线程上取消它,并检查是否在导航层次结构中显示或推送ViewController
loadingIndicator.dismiss(animated: true) {
let success = UIAlertController(title: "Successfully Uploaded", message: "", preferredStyle: .alert)
let ok = UIAlertAction(title: "Ok", style: .default, handler: { _ in
DispatchQueue.main.async {
self.dismiss(animated: true, completion: nil)
// If pushed use PopViewController on navigation
// self.navigationController?.popViewController(animated: true)
}
})
success.addAction(ok)
self.present(success, animated: true, completion: nil)
}
要检查ViewController是否正在显示,请使用
self.isBeingPresented
属性。尝试在主线程上取消它,并检查ViewController是否在导航层次结构中显示或推送
loadingIndicator.dismiss(animated: true) {
let success = UIAlertController(title: "Successfully Uploaded", message: "", preferredStyle: .alert)
let ok = UIAlertAction(title: "Ok", style: .default, handler: { _ in
DispatchQueue.main.async {
self.dismiss(animated: true, completion: nil)
// If pushed use PopViewController on navigation
// self.navigationController?.popViewController(animated: true)
}
})
success.addAction(ok)
self.present(success, animated: true, completion: nil)
}
要检查ViewController是否正在显示,请使用
self.isBeingPresented
属性。尝试取消主线程上的警报。我正在从另一个函数调用此代码,因为它是由按钮调用的。我还尝试将解雇包装在一个DispatchQueue.main.async
调用中,但这也不起作用。检查是否提供了VC?我该怎么做?更新了答案,我确信这与您的导航层次结构有关。请尝试取消主线程上的警报。我正在从另一个函数调用此代码,因为它是由按钮调用的。我也尝试过在一个DispatchQueue.main.async
调用中包装解雇,但也没有成功。检查是否有VC?我该怎么做?更新了答案,我确信这与您的导航层次结构有关。