我試圖創建一個表格視圖,其中包含動態高度的單元格,一切似乎都正常,但後來我注意到了這個奇怪的問題。 當我向下滾動列表並返回時,某些單元格似乎不能完全繪製內容。動態表格單元格高度(內容截取)
正確的內容: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;
}
我看不到照片.. – TheNavigat
對不起,應該現在修復 –
*檢查照片後* - 奇怪。從來沒有這樣的問題。那裏有多少個細胞?我的意思是,也許這是因爲內存泄漏 – TheNavigat