2017-12-22 11 views
0

내 앱은 지속성 데이터 저장소로 CoreData을 사용하고 있습니다. 아래는 내 tableview에 대한 코드입니다. 시뮬레이터에서는 잘 실행되지만, 전화로 실행하면 매우 느려집니다. 최적화에 대한 모든 제안에 감사드립니다 :)iOS 목표 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

먼저 글꼴을 맞춤 설정하고 텍스트를 설정할 때와 같이 일부 코드는 필요하지 않습니다. 다음으로 계측기 -> 프로파일을 사용하여 시간이 많이 걸리는 코드를 찾을 수 있습니다. 희망이 당신을 도울 수 있기를 바랍니다!