I have a view controller that has a tableView, and tableView has many cells.
class TimelineCell: UITableViewCell {
@IBOutlet weak var photo: UIImageView!
@IBOutlet weak var message: UITextView!
}
class TimelineViewController: UIViewController, UITableViewDataSource {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let entity = tableViewData[indexPath.row]
let cell: TimelineCell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier, forIndexPath: indexPath) as! TimelineCell
let messageAttributedString = entity.messageAttributedString
cell.message.attributedText = messageAttributedString
return cell
}
}
If messageAttributedString's length is too long and cell.message's height is too long, tableView is laggy when scrolling. If I delete updating attributedText code, the scrolling is smooth.
Any idea to solve this problem?
I tried UILabel, and the problem still existed.
Can I update attributedText in background thread? I think I can't.
I try to convert UITextView to UIImage first, and show image in cells. The tableView isn't laggy any more, but I don't think this is a good solution.