【发布时间】:2023-03-23 08:21:01
【问题描述】:
我对 Swift 有点陌生,我想不通。我有一个应该在成功的 URL 请求上显示的警报。在用户单击警报上的Ok 按钮后,我需要解除警报,并且需要呈现的控制器在导航堆栈中返回到前一个视图控制器。我没有收到任何错误,但没有任何反应。如果我在 CustomClass 中移动警报的整个代码,那么它工作正常。我假设我没有以正确的方式引用 CustomClass。任何帮助将不胜感激!
struct Alert {
static func CustomAlert(vc: UIViewController, title: String, message: String){
var title = "Title...!"
var message = "Message..."
let myAlert = UIAlertController(title: title, message: message, preferredStyle: .alert)
myAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (actin) in
myAlert.dismiss(animated: true, completion: nil)
let vc = CustomClass()
vc.GoBackToPreviousVC()
}))
vc.present(myAlert, animated: true, completion: nil)
}
}
class: CustomClass: UIViewController {
func GoBackToPreviousVC(){
navigationController?popViewController(animated: true)
}
function Download(){
code for URLRequest...
DispatchQueue.main.async {
if (self.response.Status == "200"){
Alert.CustomAlert(vc: self, title: "", message: "")
}
}
}
}
【问题讨论】: