2011-08-01 3 views
1

커스텀 UITableViewCell이 있는데, 테이블을로드하려고하면 다음과 같은 메시지가 나타납니다. issue. 여기에있는 사람이 무슨 일이 일어나고 있는지 알고 있습니까? 당신은 테이블 셀을 다시 사용할 수 있지만 적절하게 재설정하지 않으면 어떻게UITableViewCell 로딩과 함께 이상한 문제

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"FTPostCell"; 

    FTPostCell *cell = (FTPostCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[FTPostCell alloc] initWithFrame:CGRectZero] autorelease]; 
    } 

    //snips 

} 
- (id) initWithFrame: (CGRect)frame { 
    self = [super initWithFrame: frame]; 
    if (self) { 

     self.like_img = [[[UIButton alloc] initWithFrame:CGRectMake(5, 75, 30, 30)] autorelease]; 
     [self.like_img setImage:[UIImage imageNamed:@"favorite.png"] forState:UIControlStateNormal]; 
     [self.contentView addSubview: self.like_img]; 

     self.number_like = [[UILabel alloc] initWithFrame:CGRectMake(15, 110, 20, 12)]; 
     [self.contentView addSubview:self.number_like]; 

     self.comment_img = [[[UIButton alloc] initWithFrame:CGRectMake(5, 120, 30, 30)] autorelease]; 
     [self.comment_img setImage:[UIImage imageNamed:@"comment.png"] forState:UIControlStateNormal]; 
     [self.contentView addSubview: self.comment_img]; 

     self.number_comment = [[UILabel alloc] initWithFrame:CGRectMake(15, 155, 20, 12)]; 
     [self.contentView addSubview:self.number_comment]; 

     self.type_img = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 40, 30, 30)] autorelease]; 
     [self.contentView addSubview:self.type_img]; 

     self.avatar = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 30)] autorelease]; 
     [self.contentView addSubview:self.avatar]; 

     self.post_title= [[[UILabel alloc] initWithFrame:CGRectMake(50, 30, 700, 50)] autorelease]; 
     [self.contentView addSubview:self.post_title]; 

     self.post_detail = [[[UILabel alloc] initWithFrame:CGRectMake(50, 10, 700, 10)] autorelease]; 
     [self.contentView addSubview:self.post_detail]; 

     self.post = [[[DTAttributedTextView alloc] initWithFrame:CGRectMake(50, 60, 600, 500)] autorelease]; 
     self.post.textDelegate = self; 
     [self.contentView addSubview:self.post]; 

     //self.postView = [[[DTAttributedTextContentView alloc] initWithFrame:CGRectMake(50, 60, 600, 500)] autorelease]; 
     //[self.contentView addSubview:self.postView]; 


     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lazyImageDidFinishLoading:) name:@"DTLazyImageViewDidFinishLoading" object:nil]; 

    } 

    return self; 
} 


- (void)layoutSubviews { 
    [super layoutSubviews]; 
    [self.post_title sizeToFit]; 
    [self.post_detail sizeToFit]; 
    [self.post_detail setFont:[UIFont fontWithName:@"ArialMT" size:12.0]]; 
    [self.post_title setFont:[UIFont fontWithName:@"Arial-BoldMT" size:18.0]]; 
    [self.number_comment setFont:[UIFont fontWithName:@"Arial-BoldMT" size:14.0]]; 
    [self.number_like setFont:[UIFont fontWithName:@"Arial-BoldMT" size:14.0]]; 
    [self.number_like setTextColor:[UIColor grayColor]]; 
    [self.number_comment setTextColor:[UIColor grayColor]]; 
    [self.post_title setTextColor:[UIColor blueColor]]; 

} 

답변

0

:

는 여기에 몇 가지 코드입니다. 일반적으로 서식있는 텍스트 셀의 경우 레이아웃을 지정하고 새 셀을 렌더링하는 오버 헤드가 셀을 다시 설정하는 것보다 적은 경우 셀을 다시 사용하지 않을 수 있습니다.

+0

그래서 솔루션은 셀을 전혀 재사용하지 않는 것입니까? – adit

+0

수퍼 뷰에서 DTAttributedTextView를 제거하고 다시 할당하여 prepareForReuse를 구현해 보았습니다. 작동하지 않습니다. – adit

+0

그리고 셀 재사용 문제가있는 경우 왜 처음으로 뷰가로드 되는가? 그것은 재사용하지 않는다. 이것은 잘 일어난다. – adit