2017-01-14 4 views
0

誰もがこの問題を手助けできるかどうかは、比較的新しいものです。Swift、CoreAnimationのUIの変更:コミットされていないCATransactionの警告、削除されたスレッド

私は、サービスコール中にローディングスピナーにボタンを変更してラベルを作成し、そのコールの応答メッセージにすぐに変更しようとしています。

私は私のログにこのエラーが表示されます。助けを

CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces.

感謝を。私はこれらのコアアニメーションエラーについて読んだことがありますが、ここでのすべてが非同期で行われているので、私が間違っていることがわかりません。あなたも、メインスレッドの外に移動した前

 self.pastebinButton.isEnabled = false 
     self.pastebinButton.title = "" 
     self.pastebinProgressIndicator.startAnimation(nil) 

     pastebinAPI.postPasteRequest(urlEscapedContent: urlEscapeText(txt: text)) { pasteResponse in 

      DispatchQueue.main.async { 
       self.pastebinProgressIndicator.stopAnimation(nil) 
       if pasteResponse.isEmpty { 
        self.pastebinButton.title = "Error" 
       } else { 
        self.pastebinButton.title = "Copied!" 
       } 
      } 

      DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2), execute: { 
       self.pastebinButton.title = "Pastebin" 
       self.pastebinButton.isEnabled = true 
      }) 
+0

'pastebinProgressIndicator'は' UIProgressView'ですか? – Pierce

+0

お返事ありがとうございます。これは 'NSProgressIndicator'です –

+0

私はMac OS用に開発しています –

答えて

1

ですから、DispatchQueue.main.asyncを呼び出している:ここで

は修正されたコード、感謝@Pierceです。これは不要です。また、バックグラウンドスレッドで作業していると、メインスレッドにディスパッチせずにUI(ボタンのタイトル)を更新しています。バックグラウンドスレッドでUIを更新しないでください。

if !text.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines).isEmpty { 

    self.pastebinButton.title = "" 
    self.pastebinProgressIndicator.startAnimation(nil) 

    pastebinAPI.postPasteRequest(urlEscapedContent: urlEscapeText(txt: text)) { pasteResponse in 

     // Clean up your DispatchQueue blocks 
     DispatchQueue.main.async { 
      self.pastebinProgressIndicator.stopAnimation(nil) 
      if pasteResponse.isEmpty { 
       self.pastebinButton.title = "Error" 
      } else { 
       self.pastebinButton.title = "Copied!" 
      } 
     } 

     DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2), execute: { 
      self.pastebinButton.title = "Pastebin" 
      self.pastebinButton.isEnabled = true 
     }) 

    } 
} else { 
    Utility.playFunkSound() 
} 
関連する問題