我使用以下代码动态更改单元格高度。但它没有显示任何内容。谁能帮我做到这一点。
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(!self.customCell){
self.customCell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
}
//Cell configuration
self.customCell.title.text = vendor[indexPath.row];
int quoteIndex = indexPath.row % [vendor count];
self.customCell.description.text = message[quoteIndex];
//Cell Layout
[self.customCell layoutIfNeeded];
//Height of cell
CGFloat height = [self.customCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
// CGFloat height = 240;
return height;
}
最佳答案
在自定义单元格中,描述标签 - 设置行数 = 0
[Label SizeToFit] 会帮助你。
此代码可能对您有所帮助。
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(!self.customCell){
self.customCell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
}
//Cell configuration
self.customCell.title.text = vendor[indexPath.row];
int quoteIndex = indexPath.row % [vendor count];
self.customCell.description.text = message[quoteIndex];
[self.customCell.description sizeToFit];
float height = (CGRectGetMaxY(self.customCell.description.frame) + 5);
return height;
}
谢谢
关于ios - 单元格高度无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24607319/