【问题标题】:How to custimize the height of Table Cell with respect to height of image in it?如何自定义表格单元格相对于其中图像高度的高度?
【发布时间】:2012-11-16 02:01:29
【问题描述】:

我有一个 UITableView,我在单元格中显示不同的图像,每个图像都有不同的高度,我如何根据图像的高度自定义单元格高度?

【问题讨论】:

    标签: iphone objective-c xcode uitableview


    【解决方案1】:

    实现UITableViewDelegate 方法– tableView:heightForRowAtIndexPath:。请参阅documentation

    例如,如果您正在使用 Interface Builder,请从表视图中右键拖动到控制器本身,在视图控制器的类声明中的 UIViewController 之后添加 <UITableViewDelegate>,然后将类似这样的内容添加到类.m文件:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
      UIImage *image = imagesArray[indexPath.row];
      return image.size.height + 5; // 5 = margin.
    }
    

    【讨论】:

    • 我假设您有一组图像,称为imagesArray。您可能将图像存储在某个地方?
    猜你喜欢
    • 2013-11-04
    • 1970-01-01
    • 2015-07-13
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多