質問編集履歴

1

読み込み速度が遅い理由を追加

2018/11/01 13:17

投稿

HNSZ
HNSZ

スコア33

test CHANGED
File without changes
test CHANGED
@@ -41,3 +41,45 @@
41
41
  表示されないかもしれないタブの情報を取得するのは無駄なのかなとも思っています。
42
42
 
43
43
  世間一般的にはどうなのかご存知でないでしょうか。
44
+
45
+
46
+
47
+ ■読み込み速度が遅い理由
48
+
49
+ 「 let imageData = try? NSData(contentsOf: url! as URL,options: NSData.ReadingOptions.mappedIfSafe)」の処理に約1秒かかってしまいます。。。
50
+
51
+
52
+
53
+ ```
54
+
55
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
56
+
57
+ let cell = tableView.dequeueReusableCell(withIdentifier: "ContentsTableViewXib") as! ContentsTableViewXib
58
+
59
+ cell.selectionStyle = UITableViewCellSelectionStyle.none
60
+
61
+
62
+
63
+ let dict = items[(indexPath as NSIndexPath).row] //jsonデータを代入
64
+
65
+
66
+
67
+ let contentsTableImage = cell.viewWithTag(3) as! UIImageView
68
+
69
+ imageURL = dict["Image"] as? String //0.000(s) //dictから画像URLを取得
70
+
71
+ let url = NSURL(string: "(imageURL!)") //0.000(s) 
72
+
73
+ let imageData = try? NSData(contentsOf: url! as URL,options: NSData.ReadingOptions.mappedIfSafe) // 1.179(s)
74
+
75
+ let img = UIImage(data:imageData! as Data) //0.030(s)
76
+
77
+ contentsTableImage.image = img //0.000(s)
78
+
79
+
80
+
81
+ return cell
82
+
83
+ }
84
+
85
+ ```