【问题标题】:UIActivityIndicator Disappear Before Image Loaded in SwiftUIActivityIndi​​cator 在 Swift 中加载图像之前消失
【发布时间】:2017-08-11 06:54:59
【问题描述】:

我有这样的代码

startAnimating(CGSize(width: 100, height: 100), message: "Loading...", type: NVActivityIndicatorType.pacman, displayTimeThreshold: 5, minimumDisplayTime: 5)
    self.view.makeToastActivity(.center)
    DispatchQueue.global(qos: .background).async {            
        //self.view.addSubview(collectionNews)
        //activityIndicatorView.stopAnimating()
         DispatchQueue.main.async {
            self.myGroup.enter()
            self.view.isUserInteractionEnabled = false
            self.view.window?.isUserInteractionEnabled = false
            self.getJsonFromUrl()
            self.collectionNews.dataSource = self
            self.collectionNews.delegate = self
            self.collectionNews.contentInset = UIEdgeInsetsMake(0, 5, 0, 5)
            self.getJsonFromUrl2()
            self.myGroup.leave()
            self.refresh_now()
            self.myGroup.notify(queue: .main) {
                self.stopAnimating()
                self.view.hideToastActivity()
                self.view.isUserInteractionEnabled = true
                self.view.window?.isUserInteractionEnabled = true
            }
        }            
    }

但是,当我运行应用程序时,活动指示器总是在所有图像加载成功之前消失。当用户在所有内容加载成功之前尝试滚动应用上的每个位置时,这将触发错误。

甚至,我使用了 2 个活动指示器,并且它们总是在加载所有内容之前消失。

谁能给我建议,我做错了哪一个?

【问题讨论】:

  • 你在 tableView 中的哪里显示图像?你把这段代码放在哪里?你能让你的问题更容易理解吗?
  • 你可以为活动指示器@christ2702添加时间

标签: ios swift xcode uiactivityindicatorview activity-indicator


【解决方案1】:

您正在主线程中加载内容。您可以在后台从服务器加载/获取数据,并在主线程中更新您的 UI。喜欢:

startAnimating(CGSize(width: 100, height: 100), message: "Loading...", type: NVActivityIndicatorType.pacman, displayTimeThreshold: 5, minimumDisplayTime: 5)
    self.view.makeToastActivity(.center)
    DispatchQueue.global(qos: .background).async {            
        //self.view.addSubview(collectionNews)
        //activityIndicatorView.stopAnimating()

            self.myGroup.enter()
            self.view.isUserInteractionEnabled = false
            self.view.window?.isUserInteractionEnabled = false
            self.getJsonFromUrl()
            self.collectionNews.dataSource = self
            self.collectionNews.delegate = self
            self.collectionNews.contentInset = UIEdgeInsetsMake(0, 5, 0, 5)
            self.getJsonFromUrl2()
            self.myGroup.leave()
            self.refresh_now()

       DispatchQueue.main.async {
            self.myGroup.notify(queue: .main) {
                self.stopAnimating()
                self.view.hideToastActivity()
                self.view.isUserInteractionEnabled = true
                self.view.window?.isUserInteractionEnabled = true
            }
        }            
    }

【讨论】:

  • 很抱歉,但它没有给出不同的结果。请帮帮我
  • @christ2702,请您调试和检查。除了这种方法之外,您还隐藏了加载程序。检查是否有任何方法与此方法一起被调用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多