【发布时间】:2018-12-27 15:25:14
【问题描述】:
我有 uicollectionview 作为聊天视图,而 uicollectionviewcell 是聊天消息。有些消息有链接,我的 collectionView(_:cellForItemAt:) 调用 setupCell(cell:message:) 函数
fileprivate func setupCell(cell: ChatMessageCell, message: RequestMessage) {
var attributedString = NSMutableAttributedString()
if let url = message.url {
attributedString = NSMutableAttributedString(string: message.messageText, attributes:[NSAttributedStringKey.link: url, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16)])
cell.textView.attributedText = attributedString
cell.textView.delegate = self
}
}
问题是当我快速滚动时,其他单元格也会变成链接。
【问题讨论】:
标签: ios swift cocoa-touch uicollectionview nsattributedstring