gpt4 book ai didi

ios - ui 事件指示器未显示在 viewcontroller 中,其中有 TableView 和 web View ?

转载 作者:行者123 更新时间:2023-11-29 11:36:36 26 4
gpt4 key购买 nike

var actInd: UIActivityIndicatorView = UIActivityIndicatorView()
actInd.frame = CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0)
actInd.center = view.center
actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
view.addSubview(actInd)
getinfo()
actInd.startAnimating()
func getinfo(){
//in this function theres is few image parsing codes, for table view

for i in 0 ..< minuscurent1.count
{
let adict:NSDictionary = minuscurent1[i] as! NSDictionary

let bdict:NSDictionary = adict.object(forKey: "snippet") as! NSDictionary
let cdict:NSDictionary = bdict.object(forKey: "resourceId") as! NSDictionary
let ddict:NSDictionary = bdict.object(forKey: "thumbnails") as! NSDictionary
let edict:NSDictionary = ddict.object(forKey: "medium") as! NSDictionary

self.videolist.add(bdict.object(forKey: "title") as! String)
self.videoId.add(cdict.object(forKey: "videoId") as! String)
self.image.add(edict.object(forKey: "url") as! String)
}
DispatchQueue.main.async {
self.actInd.stopAnimating()
self.actInd.hidesWhenStopped = true
self.videotable.reloadData()
}

我希望事件指示器从头开始,并在加载所有图像和 WebView 时结束它。但是事件指示器没有显示。我不知道代码有什么问题。感谢任何帮助...

最佳答案

您的图片加载发生在主线程中,因此会阻止 UI 更新。您必须在后台线程中完成繁重的工作,并且仅在完成后更新事件指示器。

DispatchQueue.global(qos: .background).async {
// Background Thread
// put your image loading here (for-loop)


DispatchQueue.main.async {
// Run UI Updates
self.actInd.stopAnimating()
self.actInd.hidesWhenStopped = true
self.videotable.reloadData()
}
}

关于ios - ui 事件指示器未显示在 viewcontroller 中,其中有 TableView 和 web View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48861683/

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