2011-08-01 25 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

私はprepareForReuseを実装しようとしました。スーパービューからDTAttributedTextViewを削除し、再度割り当てます。それは動作しません.. – adit

+0

そして、それがセルの再利用の問題だったのなら、初めてビューが読み込まれるときですそれは再使用していない..これも同様に起こる – adit