2017-12-22 21 views
0

私のアプリケーションは、永続性データストレージとしてCoreDataを使用しています。以下は私のテーブルビューのコードです。シミュレータ上では正常に動作しますが、電話で実行すると非常に遅くなります。最適化の上の任意の提案が高く評価され:)iOS Objective C - UITableViewパフォーマンスの問題

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 
Journal* journal = [self.fetchedResultsController objectAtIndexPath:indexPath]; 

cell.titleLabel.text = journal.title.uppercaseString; 
cell.titleLabel.font = [UIFont fontWithName:@"SourceSansPro-Bold" size:25]; 
cell.titleLabel.textColor = [UIColor blackColor]; 

cell.detailLabel.text = journal.detail; 
cell.detailLabel.font = [UIFont fontWithName:@"SourceSansPro-SemiBold" size:18]; 
cell.detailLabel.textColor = [UIColor blackColor]; 

NSDate *currentDate = journal.timeStamp; 

cell.dateLabel.text = [self.dateFormatter stringFromDate: currentDate]; 
cell.dateLabel.font = [UIFont fontWithName:@"SourceSansPro-SemiBold" size:16]; 
cell.dateLabel.textColor = [UIColor blackColor]; 

cell.locationLabel.text = [NSString stringWithFormat:@"%@, %@", journal.city, journal.country]; 
cell.locationLabel.font = [UIFont fontWithName:@"SourceSansPro-SemiBold" size:18]; 
cell.locationLabel.textColor = [UIColor blackColor]; 

cell.tempLabel.text = [NSString stringWithFormat:@"%g°C", round(journal.temp)]; 
cell.tempLabel.font = [UIFont fontWithName:@"SourceSansPro-SemiBold" size:18]; 
cell.tempLabel.textColor = [UIColor blackColor]; 
cell.weatherIcon.image = [UIImage imageNamed:journal.condition]; 

cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageWithData:journal.image] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]; 
cell.backgroundView.contentMode = UIViewContentModeScaleAspectFill; 
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageWithData:journal.image] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]; 
cell.selectedBackgroundView.contentMode = UIViewContentModeScaleAspectFill; 
cell.backgroundView.alpha = 0.5; 
cell.selectedBackgroundView.alpha = 0.5; 

return cell; 
} 
+1

コードを作成して効率化した場合、[Code Review](https://codereview.stackexchange.com/) –

+0

に属しています。まず、楽器を使用して、遅れている部分の時間を測定することをお勧めします。 –

答えて

1

をあなたが低FPSを経験しているので、このAPIの使用状況の遅れ:

[UIImage imageWithData:journal.image] 

テーブルビューは、それぞれの新しいをロードするようにUIImageimageWithData:方法は、非同期ではありませんそれを実行しながらアプリケーションをロックして、データを処理する必要があります。

バックグラウンドスレッドで画像をロード/作成/キャッシュする非同期的な方法を見つけて、UIを反応させるようにしてください。
この人気イメージのロード/キャッシングライブラリSDWebImageをチェックしてください。

0

まず、セルをカスタマイズすることができます。フォントやテキストの色を毎回設定するなどのコードは不要です。 次に、instrument - > Profileを使用して、時間のかかるコードを見つけることができます。 それがあなたを助けることを願っています!

関連する問題