您需要在后台进行数据加载,以便UI可以继续运行。
下面是您想要的一般模式:
// start the activity indicator here
DispatchQueue.global(qos: .background).async {
// Data loading / processing here
DispatchQueue.main.async {
// stop the activity indicator here and make any other UI updates
}
}
在您的特定情况下:
override func viewDidLoad() {
super.viewDidLoad()
RappleActivityIndicatorView.startAnimating()
DispatchQueue.global(qos: .background).async {
// the API function
let a_Json = getDataJson(symbol: a)
let b_Json = getdDataJson(symbol: b)
DispatchQueue.main.async {
RappleActivityIndicatorView.stopAnimating()
}
}
}