gpt4 book ai didi

swift - 加载指示器无法正常工作

转载 作者:行者123 更新时间:2023-11-30 13:10:41 26 4
gpt4 key购买 nike

这是我的代码。我想在传递数据并将数据添加到数据库期间单击按钮时显示一个指示器。我该如何修复它?

@IBAction func addWishList(sender: AnyObject) {
self.loading.startAnimating()
addMovie(showMovie!) // Database add method.
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
let controller : WishListViewController = segue.destinationViewController as! WishListViewController

if segue.identifier == "segue" {
controller.user = self.tmpUser // data from Facebook to pass another controller
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.loading.stopAnimating()
})
}
})
}

最佳答案

您的 addMovie 阻塞主队列。您需要给予一些延迟才能将其添加到下一个运行循环。尝试使用:

@IBAction func addWishList(sender: AnyObject) {
self.loading.startAnimating()
//This will add to next main run loop.
let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.0 * Double(NSEC_PER_SEC)))
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
addMovie(showMovie!) // Database add method.

})
}

关于swift - 加载指示器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38766808/

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