【问题标题】:Is there any way to change UITableView height from custom UITableViewCell class?有没有办法从自定义 UITableViewCell 类更改 UITableView 高度?
【发布时间】:2014-03-17 21:56:06
【问题描述】:

我正在尝试制作 Instagram 之类的应用,但我卡在了 Feed 屏幕上。

我将评论部分设为 UITableView。所以我的 UITableView 的自定义单元格类中有 UITableView。没关系。

我的问题是:如何从自定义表格视图单元格类更改主提要表格视图的高度?

评论表视图的行高会根据其中的文本(长度)动态变化。动态变量是我打算使用的评论表视图的高度。

注意:我不能分享任何代码,因为它是我们公司的机密项目。

干杯

【问题讨论】:

    标签: ios objective-c uitableview instagram


    【解决方案1】:

    理想情况下,您应该使用自动布局来调整UITableViewCellUITableView 中特定行的高度。有一个Stackoverflow thread 详细讨论了这一点。

    【讨论】:

      【解决方案2】:

      使用tableView委托方法heightForRowAtIndexPath设置tableViewCell的高度

      – (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
      

      使用boundingRectWithSize方法找到动态注释标签部分的高度,并在tableviewcell中添加其他静态内容高度,并在上述delagate方法中设置此高度。

      - (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options context:(NSStringDrawingContext *)context
      

      【讨论】:

      • 我在调整评论单元格大小时使用了 boundingRectWithSize 方法,谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 2011-01-09
      • 2019-05-18
      相关资源
      最近更新 更多