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