簡體   English   中英

重新加載時停止 tableview 自動滾動

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM