追記
質問タイトルと回答の方向性が異なっていたため。
適切な質問タイトルに変更しました。
先程、元tabelviewcellをタップしてAPI取得して結果を次tabelviewcellへ遷移(e.g.push)して表示について教えて頂いたのですが。
さらにAPIで表示されたtabelviewcellからタップして次のAPIを取得して3つめのtabelviewcellにAPIの結果をcellに描画したいのですが。
結果動作はするのですが,数百バイトのAPIを取ってきているのに3つ目の画面遷移まで10~20秒程度かかりdebugを見ると
This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
というログが次のtableviewに遷移するまでに29回でました。
1つ前のAPIをtabelviewcellに描画するときには全く出てなかったので原因がわかりません。
描画する前にAPIで値を取って遷移後に配列からcellに描画しているためbackgroundでlayoutをいじってるつもりもないのですが。
autolayoutを無効にすることで直るか試してみたいのですがSwift3でのコードをご教授ください。
移動前のcellタップコード
Swift3
1// Cell が選択された場合 2 override func tableView(_ table: UITableView,didSelectRowAt indexPath: IndexPath) { 3 4 let ip = indexPath.row 5 6 let url = "http://api.jp/API/"+self.appDelegate.yAR[ip]+".json" 7 8 //#add array初期化 9 self.appDelegate.zAR = [] 10 11 let nsUrl = NSURL(string: url) 12 let task = URLSession.shared.dataTask(with: nsUrl as URL, completionHandler: {data, response, error in 13 // リソースの取得が終わると、ここに書いた処理が実行される 14 var json = JSON(data: data!) 15 // 各配列に情報を突っ込む 16 for i in 0 ..< 100{ 17 18 if(json["items"][i]["goods"].string == nil) 19 { 20 print("-----API取得完了----",self.appDelegate.zAR) 21 //performSegue(withIdentifier: "toSong", sender: nil) 22 break 23 } 24 else 25 { 26 self.appDelegate.zAR.append(json["items"][i]["song"].stringValue) 27 } 28 } 29 print("移動ーー") 30 //このログが出てから10~20秒立って遷移先のviewdidloadを読みそれから上に書いたログが大量に出ます。 31 32 self.performSegue(withIdentifier: "toC", sender: nil) 33 }) 34 task.resume() 35 }
移動後のコード
import UIKit import SwiftyJSON import Alamofire class SongTableViewController: UITableViewController{ override func viewDidLoad() { super.viewDidLoad() // タイトルを付けておきましょう self.title = "test" print("view did load 通過") //このログを通過後に以下ログがたくさん出ます /* This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes. */ } var appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate //Table Viewのセルの数を指定 override func tableView(_ table: UITableView, numberOfRowsInSection section: Int) -> Int { return self.appDelegate.zAR.count } //各セルの要素を設定する override func tableView(_ table: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { //tableCell の ID で UITableViewCell のインスタンスを生成 let cell = table.dequeueReusableCell(withIdentifier: "zCell", for: indexPath) // Tag番号 20 で UILabel インスタンスの生成 let zcell = table.viewWithTag(20) as! UILabel zcell.text = "\(self.appDelegate.zAR[indexPath.row])" return cell } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/23 07:20
2016/09/23 07:21 編集
2016/09/23 09:47