UITableViewCell加载的奇怪问题

时间:2011-08-01 06:33:12

标签: iphone objective-c ipad uitableview

我有一个自定义的UITableViewCell,当我尝试加载表时,我得到了以下issue。这里有谁知道发生了什么事?

以下是一些代码:

- (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]];

}

1 个答案:

答案 0 :(得分:0)

如果您重复使用表格单元格但未正确重置它们,则会发生这种情况。通常,对于富文本单元格,如果布局和渲染新单元格的开销小于重置单元格,则可能不希望重复使用单元格。