2017-08-11 63 views
0

加載之前我有這樣UIActivityIndi​​cator消失形象斯威夫特

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個活動指示器,並且它們都在每個加載的東西之前總是消失。

任何人都可以給我建議,哪一個我做錯了?

+1

你在哪裏顯示圖像在tableView中?你在哪裏把這個代碼?你能讓你的問題更容易理解嗎? –

+0

你可以增加活動指標的時間@ christ2702 –

回答

0

您正在加載主線程中的內容。您可以在後臺加載/從服務器獲取數據,並在主線程中更新您的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 
      } 
     }    
    } 
+0

對不起,但它沒有給出不同的結果。請幫幫我 – christ2702