1

我的UITableView. 滚动时,单元格中的A UIView(浅灰色背景)似乎无缘无故地填充了单元格。

这是它的外观:

这是上下滚动后的外观:在此处输入图像描述

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    CustomTableViewCell *cell = (CustomTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    [self.tableView registerNib:[UINib nibWithNibName:@"CustomTableViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];

    NSArray *post = [posts objectAtIndex:[indexPath row]];
    NSString *name = [post objectAtIndex:0];
    NSString *school = [post objectAtIndex:1];
    NSString *profilePicture = [post objectAtIndex:2];
    NSString *status = [post objectAtIndex:3];

    [cell.name setText:name];
    [cell.school setText:school];
    [cell.status setText:status];

    #define kMaxHeight 300.f
    cell.status.contentSize = [cell.status.text sizeWithFont:[UIFont systemFontOfSize:14]
                                           constrainedToSize:CGSizeMake(295, kMaxHeight)
                                               lineBreakMode:UIViewAutoresizingFlexibleHeight];

    [cell.status setFrame:CGRectMake(cell.status.frame.origin.x, cell.status.frame.origin.y, 295, cell.status.contentSize.height + 25)];

    float height = 60 + cell.status.contentSize.height;

    [cell.backgroundView setFrame:CGRectMake(cell.backgroundView.frame.origin.x, cell.backgroundView.frame.origin.y, cell.backgroundView.frame.size.width, height - 10)];

    [cell.backgroundView clipsToBounds];
    [cell clipsToBounds];

    return cell;

}

我究竟做错了什么?

4

0 回答 0