重新加载单元格时,表格视图单元格闪烁和位置更改



在表格视图单元格中的应用程序中,单击"更多"按钮时,我正在使用"更多"按钮来加载更多内容。 因此,单击更多按钮时,我正在重新加载该特定单元格。 但是当我重新加载该单元格时,该单元格会向上并发生一些闪烁效果。 我希望它像Instagram一样流畅,当我们点击更多按钮时,它只是增加单元格的高度而没有任何位置变化。

这是我的代码 :

@objc func btnMorePressed(sender : UIButton) {
let indexPath = NSIndexPath(row: sender.tag, section: 0)
let cell : FeedTableViewCell = (tblQuote.cellForRow(at: indexPath as IndexPath) as? FeedTableViewCell)!
cell.btnMore.isHidden = true
cell.lblCaption.numberOfLines = 0
quoteArray[indexPath.row].numberOfLines = 3
tblQuote.reloadRows(at: [indexPath as IndexPath], with: .none)
tblQuote.beginUpdates()
tblQuote.endUpdates()
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}

将顺序更改为:

tblQuote.beginUpdates()
tblQuote.reloadRows(at: [indexPath as IndexPath], with: .automatic)
tblQuote.endUpdates()

最新更新