現在、Twitterのタイムラインを表示するUITableViewを作っているのですが、どうしてもスクロールがカクついてしまいます。
セル生成の処理速度を測ってみたところ、テキストの分量が50文字くらいになると生成するのに0.01秒を超えてしまいます。
StoryboardでUITextViewのSelectableとDetectionのLinkをtrueにしています。
Swift
1func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 2 3 self.tweet = self.TweetsJson![indexPath.row] 4 var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as? TableViewCell 5 6 cell!.TextView.text = tweet!["text"].stringValue; 7 8 cell!.nameLabel.text = tweet!["user"]["name"].stringValue; 9 cell!.screenNameLabel.text = "@" + tweet!["user"]["screen_name"].stringValue; 10 11 let url : NSURL = NSURL(string:tweet!["user"]["profile_image_url"].stringValue.stringByReplacingOccurrencesOfString("normal", withString: "bigger"))! 12 13 14 cell!.iconImage.af_setImageWithURL(url,placeholderImage: UIImage(named: "icon_placeholder")!) 15 16 return cell! 17 }
TextView
Swift
1cell!.TextView.text = tweet!["text"].stringValue;
0.0032秒
nameLabel
Swift
1cell!.nameLabel.text = tweet!["user"]["name"].stringValue;
0.0012秒
screenNameLabel
Swift
1cell!.screenNameLabel.text = "@" + tweet!["user"]["screen_name"].stringValue;
0.0014秒
iconImage
Swift
1let url : NSURL = NSURL(string:tweet!["user"]["profile_image_url"].stringValue.stringByReplacingOccurrencesOfString("normal", withString: "bigger"))! 2cell!.iconImage.af_setImageWithURL(url,placeholderImage: UIImage(named: "icon_placeholder")!)
0.003秒
どうやって速度を計ったのか教えて下さい。
http://qiita.com/osamu1203/items/9160f5f4951ebe205ea3
こちらを参考にして測りました
cellForRowAtIndexPathの最初と最後の間の時間を計ると0.01秒overだったということでしょうか?もう少し細かい処理単位で時間を測って、もしくは、各処理を1つずつコメントアウトして、どの処理が重いのか特定して下さい。
おっしゃる通り最初とreturnの直前の間を測っています。
一つ一つ調べてみたところ、UILabel.textをいじっているところで時間がかかっていました。
回答2件
あなたの回答
tips
プレビュー