[英]Stop tableview auto scroll when reload
我的问题是当我点击加号或减号时,我重新加载到 tableview 是可以的,但是当它重新加载时它会自动滚动并且我的部分标题也会闪烁。 我附上了夹子以获得更多间隙。
我使用此代码重新加载 tableview
let contentOffset = tblItemList.contentOffset
tblItemList.reloadData()
tblItemList.layoutIfNeeded()
tblItemList.setContentOffset(contentOffset, animated: false)
添加
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath) as! ItemCell
if arrCategoryList.count > 0 {
let data = (arrCategoryList[indexPath.section].product_list ?? [])[indexPath.row]
cell.setItemData(data)
if data.is_added {
cell.btnAdd.isHidden = true
cell.lblQuantity.text = "\(data.product_quantity)"
}
else {
cell.btnAdd.isHidden = false
}
cell.btnMinus.tag = indexPath.row
cell.btnPlus.tag = indexPath.row
cell.btnAdd.tag = indexPath.row
cell.btnAdd.addTarget(self, action: #selector(onClickAdd), for: .touchUpInside)
cell.btnPlus.addTarget(self, action: #selector(onClickPlus), for: .touchUpInside)
cell.btnMinus.addTarget(self, action: #selector(onClickMinus), for: .touchUpInside)
}
return cell
}
您正在重新加载整个 tableView 以更新单个单元格。 只需使用tableView.reloadRows(at: [IndexPath(row: //row go here, section: //section go here)], with: .automatic)并且标题闪烁可能是因为您使用 UItableViewCell 作为标题视图。 只需在 XIB 的帮助下使用 UITableHeaderFooterView 并将其注册为 HeaderView 在您的 tableView 中。 只看这个标题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.