我正在尝试创建一个函数来显示和解除Swift 3中的ProgressDialog.但在此代码中,对话框不会从视图控制器中消失.
func showLoadingDialog(show : Bool) {
if show {
self.alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
loadingIndicator.hidesWhenStopped = true
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
loadingIndicator.startAnimating()
self.alert.view.addSubview(loadingIndicator)
self.present(self.alert, animated: true, completion: nil)
}else{
self.dismiss(animated: false, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试了以下方法来关闭此对话框,但它们都没有工作:
self.alert.view.removeFromSuperview()
self.alert.view.alpha = 0
self.presentingViewController?.dismiss(animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
请帮我.如果你们有任何替代解决方案,请提出建议.
小智 4
//尝试这个
func showLoadingDialog(show : Bool) {
if show {
if self.alert == nil{
self.alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
loadingIndicator.hidesWhenStopped = true
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
loadingIndicator.startAnimating()
self.alert.view.addSubview(loadingIndicator)
}
if !self.alert.isBeingPresented {
self.present(self.alert, animated: true, completion: nil)
}
}else{
self.alert.dismiss(animated: false, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1095 次 |
| 最近记录: |