func create()
{
self.Instance!.viewController!.loadCategory(category: 0)
/*
repeat
{
print("Loading category section!")
}
while (self.Instance!.viewController!.isLoading!)
*/
}
上面的代码表明我可以设置延迟,直到 isLoading 为 false;但是,它永远不会变为 false,因为它锁定了线程。
我怎样才能在后台运行它?
谢谢
LoadCategory 使用 wkwebview 加载网站的类别页面,并在加载网页内容时将 isLoading 设置为 true,在全部加载完成后将其设置为 false
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
{
print("Finished navigating to url \(String(describing: webView.url))")
self.isLoading = false
}
这是我的函数,在完成加载内容后将其设置为 self.isLoading 为 false。
最佳答案
大中央调度
在 Swift 中,您可以使用 Grand Central Dispatch
在给定延迟后执行闭包这是代码
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
print("This will be executed 2 seconds in the future")
}
Don't forget to
import Foundation
关于ios - 如何在 iOS Swift 中设置延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43857133/