我在自定义单元格中有一个 UIImageView。如果单元格中没有要显示的图像,则单元格高度应自动减小。(在这种情况下,ImageView 高度应为零)。如何在 xib 中为此指定约束?
最佳答案
您的UITableView
数据源应该表示该图像的存在。
您应该使用以下委托(delegate)方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.dataSource[indexPath.rox].imageExists) {
return 50.0; // Change to your value with image
}
return 10.0; // Change to your value without image
}
关于ios - 根据 UIImageView 大小自定义单元格高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30908000/