2011-06-14 3 views
0

저는 궁금 해서요, UITableViewCell의 사용자 정의 backgroundView를 설정하는 데 더 좋은 성능을 가진 것은 무엇입니까?backgroundView 설정을위한 성능 향상 : willDisplayCell 또는 init?

옵션 0) 서브 클래스있는 UITableViewCell의 init 메소드

@implementation CustomCell 
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier andReleases:(NSArray*)releases { 

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tablecell.png"]] autorelease]; 
    } 
    return self; 
} 

옵션 1) 위임 willDisplayCell 방법

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tablecell.png"]] autorelease]; 
} 
+0

질문에 대한 답변을 수락합니다. 이 경우에 나는 네가 한 것을 믿는다. 감사! – Keller

답변

4

당신이를 만들 때 한 번 배경을 설정 때문에 옵션 0이 경우에 더 낫다 셀을 표시하고 willDisplayCell은 셀을 표시 할 때마다이 값을 설정합니다. 그리고 당신은 UITableViewCells을 재사용 할 것이므로 셀을 적게 생성하고 표시 할 것입니다.

그러나 조기 최적화를 피하고 성능이 좋지 않을 때만 최적화하십시오.