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