【发布时间】:2017-07-31 08:15:07
【问题描述】:
我正在尝试使用大小调整视图在集合视图中创建动态单元格大小。
如果我使用文本,一切正常,但是当我更改为属性文本时,一切都会崩溃和燃烧。
我有一个带有 UIlabel 的 nib 文件
let sizingView = Bundle.main.loadNibNamed("MyNib", owner: self, options: nil)?[0] as? MyCell
然后我将动态文本发送到单元格
sizingView.configureCell(promo: promo)
在单元格 I 中
func configureCell(promo:CMSPromotion) {
if let mainAttributedString = promo.content?.htmlAttributedString() {
mainText.attributedText = mainAttributedString
}
}
我的 HTML 属性
// Convert HTML to NSAttributedString
func htmlAttributedString() -> NSMutableAttributedString? {
guard let data = self.data(using: String.Encoding.utf16, allowLossyConversion: false) else { return nil }
guard let html = try? NSMutableAttributedString(
data: data,
options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil) else { return nil }
return html
}
我可以在所有 Google 中找到的对 setSizeHasBeenSet 的唯一引用是 _UIFlowLayoutItem 但我不明白为什么这是相关的。
我在 UICollectionView sizeForItemAt IndexPath 但经过检查,它不是重复的,因为提供的代码有其他问题。
【问题讨论】:
-
你能显示整个错误信息吗? “发送到实例的无法识别的选择器”给出了调用的方法和不匹配的类对象。还有堆栈跟踪?