私のアプリケーションは、永続性データストレージとして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;
}
コードを作成して効率化した場合、[Code Review](https://codereview.stackexchange.com/) –
に属しています。まず、楽器を使用して、遅れている部分の時間を測定することをお勧めします。 –