gpt4 book ai didi

ios - Xcode, swift : alert not dismissing

转载 作者:行者123 更新时间:2023-11-30 11:15:05 25 4
gpt4 key购买 nike

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?
}
}

你好,
我有一个 View Controller AVC,它创建一个警报和一个加载指示器。
我希望使用 ZZZ 的删除功能从另一个名为 ZZZ 的 swift 文件中消除此警报。
然而,即使我的代码明确要求,ZZZ 也不会消除警报。
我该如何解决这个问题?
谢谢

最佳答案

这里共享的是用于显示警报的自定义类

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
}
}

因此,在您的 View Controller 中,您可以显示警报

let alert = Shared().waitAlert()
present(alert, animated: true, completion: {
alert.dismiss(animated: true, completion: {
//do your code
})
})

关于ios - Xcode, swift : alert not dismissing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51820664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com