reloadData后无法在tableView单元格中单击按钮

时间:2018-08-02 17:28:16

标签: ios swift swift3

我在单元中具有3个按钮和按钮动作。调用后,tableView.reloadData()无法单击到单元格中的任何按钮。

在控制器中func cellForRow调用cell?.onbuttonTappedAdd等。添加元素之后,我将其称为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!

}

1 个答案:

答案 0 :(得分:0)

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