ios TableView不同的单元格高度

use*_*418 5 tableview ios

我正在开发一个应用程序,它要求我在 TableView 中显示图片和一些文本。这些图片可以有不同的高度,所以我需要相应地改变单元格的高度。所以我覆盖了这个方法:

 - (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

如果单元格标识符只有一个静态值,则单元格内图像的高度不能动态变化。

那么我是否需要为每个单元格设置不同的单元格标识符值?还有其他方法吗?

我不能使用除 Tableview 之外的其他视图,因为我需要根据用户交互动态显示它们之间的一些单元格。

谢谢。

Ref*_*l.S 0

仅图像的示例:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    //get reference to a image
    UIImage *image = [arrImages objectAtIndex:indexPath.row];

    //get the height of your imageview on the cell
    CGFloat imageViewHeight = image.size.height/2;//RetinaDisplay

    //return the height of the imageview (plus some padding) for your cell height
    return imageViewHeight; //add here also all other constant height's of objects that you have on your cell.
}
Run Code Online (Sandbox Code Playgroud)

有关更全面的示例,请查看我的回答:

根据 JSON 文件中的内容文本调整带有 UILabel 的自定义单元格的大小