gpt4 book ai didi

ios - SWIFT - 如何在显示 UIAlertController 消息后更改它

转载 作者:行者123 更新时间:2023-11-28 07:16:17 25 4
gpt4 key购买 nike

我想在创建 UIAlertController 后更改它的消息。在警报中,我想显示下载状态。

@IBAction func dbWillSync(sender: AnyObject) {
alert = UIAlertController(title: "SYNC",
message: "0%",
preferredStyle: .Alert)

let dismissHandler = {
(action: UIAlertAction!) in
self.dismissViewControllerAnimated(true, completion: nil)
}

alert.addAction(UIAlertAction(title: "STOP DOWNLOAD",
style: .Cancel,
handler: dismissHandler))

presentViewController(alert, animated: true, completion: nil)

download();
}

func download(){
for i in 1...100{
alert.message="\(i) %"
sleep(1)
}
}

怎么了?

谢谢

* 编辑 *****

我不知道这是不是最好的解决方案:

let thread = NSThread(target:self, selector:"download", object:nil)
thread.start()

.. 但它有效!

欢迎改进!

最佳答案

在 iOS 中,图形操作不是实时发生的。当您调用下载方法时,警报尚未显示在屏幕上。所有图形都在您退出方法并返回系统主循环后发生。因此,当您的下载方法正在运行时,甚至不会显示警报。您必须从下载本身更新您的警报消息。

关于ios - SWIFT - 如何在显示 UIAlertController 消息后更改它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25914300/

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