简体   繁体   中英

Can't Click on button in tableView cell after reloadData

I have in cell implement 3 buttons and button action. After call tableView.reloadData() can't click to any button in cell.

In controller in func cellForRow call cell?.onbuttonTappedAdd and other. Afer add element I call tabelViewReloadData.

//TableViewCell

var onButtonTappedAdd : (() -> Void)? = nil
var onButtonTappedRemove : (() -> Void)? = nil


override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}


func configureCell(orderitem: OrderItem){
    self.orderItem = orderitem!


}

func setButtonGradient(){


}
@IBAction func changeValue(_ sender: Any) {


}

@IBAction func btnAddValue(_ sender: Any) {
    if let onButtonTappedAdd = self.onButtonTappedAdd
    {
    onButtonTappedAdd()
    }
}
@IBAction func btnRemoveValue(_ sender: Any) {
    if let onButtonTappedRemove = self.onButtonTappedRemove {
    onButtonTappedRemove()
    }
}

//ViewControll cellForRow

  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

   var cell = tableViewOrderItem.dequeueReusableCell(withIdentifier: "OrderItemCheckoutCell", for: indexPath)
        as? OrderItemCheckoutCell
    var orderItem = GlobalArray.orderArrayList[indexPath.section].ListOrderItem[indexPath.row]

    cell?.configureCell(orderitem: orderItem)

   cell?.onButtonTappedAdd = {

              GlobalArray.orderArrayList[indexPath.section].ListOrderItem[indexPath.row].quantity = GlobalArray.orderArrayList[indexPath.section].ListOrderItem[indexPath.row].quantity! + (GlobalArray.orderArrayList[indexPath.section].ListOrderItem[indexPath.row].Product?.bigValue)!

   self.tableViewOrderItem.reloadData()

     self.setTotalInfo()
    }
    cell?.onButtonTappedRemove = {

                 GlobalArray.orderArrayList[indexPath.section].ListOrderItem[indexPath.row].quantity = GlobalArray.orderArrayList[indexPath.section].ListOrderItem[indexPath.row].quantity! - (GlobalArray.orderArrayList[indexPath.section].ListOrderItem[indexPath.row].Product?.bigValue)!
                       self.tableViewOrderItem.reloadData()
        }


    return cell!

}

在“ cellforRow”方法之外重新加载TableView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM