2016-10-25 34 views
0

2つのビューを作成した後、Ctrlキーを押しながらドラッグしてセグを作成することによって、ビューを作成しました。これを識別子 "functionOutput1"にセブしてくださいプログラムでトリガーされたsegueが直ちに更新されなかった後に表示される

私は関数を作成し、関数内の特定の出力に基づいて上で作成したセグをプログラムでトリガしました。

performSegue(withIdentifier: "functionOuput1", sender: self) 

ビューは大丈夫ですが、1分後までビューの内容が表示されません。

私はここで何かする必要がありますか?

EDIT: は、私はこれは、スレッドの問題である可能性がありURLRequestの

 let task = session.dataTask(with: request as URLRequest, completionHandler: { 
      data, response, error -> Void in 

      if (error != nil) { 
       // there is an error with the request 
       print("error: ", error) 

      } else { 
       // Request was successful. Check the contents of the response. 
       print("response: ", response) 

       let httpResponse = response as! HTTPURLResponse 
       if httpResponse.statusCode != 200 { 
        print("problems with server request") 

       } else { 
        print("request successful") 
        //go to next page 
        performSegue(withIdentifier: "functionOuput1", sender: self) 
       } 
      } 
     }) 

答えて

1

のコールバック関数の中で、このセグエを行っています。データは非同期で返されるためです。メインスレッドでビューの更新を実行する必要があります。次のコードでSwift 3.0でこれを行うことができます:

DispatchQueue.main.async { 
    // Your view updates here     
} 
+0

絶対に動作します!ここでiOSプログラミングを再学習することで、迅速な対応に感謝します。 "自己"を使用しています。その非同期ブロックで安全ですか? –

+1

うまくいってうれしい!ええ、非同期ブロックでの自己の使用は安全です。 – Prine

関連する問題