ibireme / YYKit

A collection of iOS components.
MIT License
13.99k stars 3.69k forks source link

YYLabel在tableviewcell上使用,设置了textParser,用highlightTapAction这个方法时下拉到其他cell的时候导致重用了 #568

Open soso-su opened 4 years ago

soso-su commented 4 years ago

contenView.hotLabel.highlightTapAction = { [weak self] (containerView, attText, range, rect) in guard let index = self?.indexPath else { return } self?.delegate?.cellDidClickInLabel(cell: self!, label: containerView as! YYLabel, textRange: range, indexPath: index) }

func cellDidClickInLabel(cell: HotTopicTableViewCell, label: YYLabel, textRange: NSRange,indexPath:IndexPath) { if let highlight = label.textLayout?.text.attribute("YYTextHighlight", at: UInt(textRange.location)) as? YYTextHighlight { let info = highlight.userInfo if let text = info?["Hoptic"] as? String{ printLog("text = (text)")
}

这个方法是异步的,我当前这个cell的内容里没有高亮的字体,但是它就走了这个方法, text直接打印出来是前面滑上去cell的高亮字体的内容