![](/img/trans.png)
[英]MFMailComposeViewController is not dismissing - Swift, Xcode
[英]Xcode, swift: alert not dismissing
class AVC: UIViewController {
override func viewDidLoad(){
let 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();
alert.view.addSubview(loadingIndicator)
viewController.present(alert, animated: true, completion: nil)
self.a()
}
func a(){
ZZZ.remove(for: self)
}
}
class ZZZ {
func remove(for viewController: UIViewController){
viewController.dismiss(animated: false, completion: nil)
//Why won't the alert created in AVC be dismissed from here?
}
}
嗨,您好,
我有一個視圖控制器AVC,它創建警報和加載指示器。
我希望使用ZZZ的刪除功能從另一個名為ZZZ的快速文件中消除此警報。
但是,即使我的代碼明確要求,也不會從ZZZ中解除警報。
我該如何解決?
謝謝
您當前正在關閉ViewController,而不是警報。 呼叫
alert.dismiss(animated: false, completion: nil)
func a() {
ZZZ().remove(for: alert)
}
這里共享的是自定義類,用於顯示警報
class Shared: NSObject {
func waitAlert() -> UIAlertController {
let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
alert.view.tintColor = UIColor.black
let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50)) as UIActivityIndicatorView
loadingIndicator.hidesWhenStopped = true
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
loadingIndicator.startAnimating();
alert.view.addSubview(loadingIndicator)
return alert
}
}
因此,在您的ViewController中,您可以顯示警報
let alert = Shared().waitAlert()
present(alert, animated: true, completion: {
alert.dismiss(animated: true, completion: {
//do your code
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.