【问题标题】:Dynamic height with tableview from HTML content来自 HTML 内容的带有 tableview 的动态高度
【发布时间】:2015-07-30 20:53:49
【问题描述】:

我想用tableview来显示留言板,

内容是HTML文件,

但是我应该如何使用 TableViewItem 的动态高度呢?

我用的

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] 
                                    initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] 
                                    options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } 
                                    documentAttributes:nil error:nil];
self.d_content.attributedText = string

显示 HTML 内容(文本 + 图像)

但是我应该如何使它具有适当的高度

或者说我应该如何计算 HTML 内容的高度?

非常感谢:)

【问题讨论】:

    标签: html objective-c uitableview dynamic height


    【解决方案1】:

    只需将数据存储在 UITableViewCell 中的 UILabel 中并使用方法

    [Label sizeToFit];
    

    因此标签将适合其中的文本,并且会随着高度而变大。

    然后使用此方法根据文本高度设置行高

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
    }
    

    @EDIT

    并将textfield的行数设置为0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      • 2018-05-09
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多