gpt4 book ai didi

ios - 动态表格单元格高度(内容截断)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:45:22 25 4
gpt4 key购买 nike

我正在尝试使用具有动态高度的单元格创建表格 View ,一切似乎都正常,但后来我注意到了这个奇怪的问题。当我向下滚动列表并返回时,一些单元格似乎没有完全绘制内容。

正确的内容:https://www.dropbox.com/s/eqsx4p6dmsofrko/Screen%20Shot%202012-05-03%20at%2010.30.11%20AM.png

内容截取:https://www.dropbox.com/s/qqelftkc5jzetk5/Screen%20Shot%202012-05-03%20at%2010.30.19%20AM.png

我在这里创建我所有的单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ItemCell";
ItemCell *cell = (ItemCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Item *item = [self.activity objectAtIndex:indexPath.row];
cell.projectLabel.text = item.project;
cell.descriptionLabel.text = item.description;
cell.timeLabel.text = item.time;
cell.timeAgoLabel.text = item.timeAgo;
//cell.avatar = [UIImageView item.avatar];

cell.descriptionLabel.numberOfLines = 0;
[cell.descriptionLabel sizeToFit];

// remove the right arrow
cell.accessoryType = UITableViewCellAccessoryNone;

//[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation: UITableViewRowAnimationNone];

return cell;
}

并使用它来改变单元格的高度:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ItemCell";
ItemCell *cell = (ItemCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

CGSize descriptionHeight = [cell.descriptionLabel.text sizeWithFont:[UIFont boldSystemFontOfSize:18.0f] constrainedToSize:CGSizeMake(265.0f, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap];

NSInteger height = cell.projectLabel.frame.origin.y + cell.projectLabel.frame.size.height;
height += descriptionHeight.height + 30;

NSLog(@"height: %d", height);

return height;
}

最佳答案

你试过调用[self setNeedsDisplay]重绘表格 View 吗?

关于ios - 动态表格单元格高度(内容截断),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10424369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com