【发布时间】:2019-02-18 07:48:34
【问题描述】:
我们必须在后台线程中将图像上传到 Web 服务。例如,我有一个主屏幕和登录屏幕。当我在主屏幕上传图像并导航到登录屏幕时,如果我在主屏幕中收到超时错误,我必须在登录屏幕中显示警报。
注意:我必须在当前视图中调用后台线程调用委托方法来显示警报,而不是在窗口根目录中使用 UIAlertController
在所有视图之上显示警报:
func alertWindow(title: String, message: String) {
DispatchQueue.main.async(execute: {
let alertWindow = UIWindow(frame: UIScreen.main.bounds)
alertWindow.rootViewController = UIViewController()
alertWindow.windowLevel = UIWindowLevelAlert + 1
let alert2 = UIAlertController(title: title, message: message, preferredStyle: .alert)
let defaultAction2 = UIAlertAction(title: "OK", style: .default, handler: { action in
})
alert2.addAction(defaultAction2)
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present(alert2, animated: true, completion: nil)
}) }
Function calling:::::
SharedClass.sharedInstance.alertWindow(title:"This your title", message:"This is your message")
上面的代码工作正常,但我必须使用委托在当前视图中显示警报怎么做?
【问题讨论】:
-
我看不出问题出在哪里...您所要做的就是在
DispatchQueue.main.async中调用delegate.whaterver,而不是显示警报...
标签: ios swift model-view-controller background alert