如何删除表格视图单元格中单选按钮的索引路径?

时间:2017-09-05 04:53:09

标签: ios uitableview swift3

这里我在单选按钮启用后有一个单选按钮,然后在选择删除后会出现删除和编辑按钮,特定单元格正在删除,但前一行单选按钮是否启用了如何避免此任何帮助?

以下是此

的代码
  @IBAction func selectRadioButton(_ sender: KGRadioButton) {
        let chekIndex = self.checkIsRadioSelect.index(of: sender.tag)
        _ = self.checkIsButtonEnable.index(of: sender.tag)
        if sender.isSelected {

        } else{
            if(chekIndex == nil){
                self.checkIsRadioSelect.removeAll(keepingCapacity: false)
                self.checkIsRadioSelect.append(sender.tag)
                self.checkIsButtonEnable.removeAll(keepingCapacity: false)
                self.checkIsButtonEnable.append(sender.tag)
                self.tableDetails.reloadData()
                self.addressSelected = true
                tableDetails.tableFooterView?.isHidden = false
                tableDetails.reloadData()
            }
        }
    }
  func deleteAction(button: UIButton) {
        let buttonPosition = button.convert(CGPoint(), to: tableDetails)
        let index = tableDetails.indexPathForRow(at: buttonPosition)
        self.tableDetails.beginUpdates()
        shippingArray.remove(at:(index?.row)!)
        self.tableDetails.deleteRows(at: [index!], with: .top)
        self.tableDetails.endUpdates()
        tableDetails.tableFooterView?.isHidden = true
        self.addressSelected = false
        self.tableDetails.reloadData()
    }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if (indexPath.section == 0)
        {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AddressTableViewCell
            tableDetails.isHidden = false
            myActivityIndicator.stopAnimating()
            let arr = shippingArray[indexPath.row]
            cell.deleteButton.tag = indexPath.row
            cell.nameLabel.text = arr["name"] as? String
            cell.addressLabel.text = arr["address"]as? String
            let mobilenumber : Any =  arr["number"] as AnyObject
            cell.mobileNumberLabel.text = "\(mobilenumber)"
            cell.radioButton.tag = indexPath.row
            cell.editButton.tag = indexPath.row
            cell.deleteButton.tag = indexPath.row
            cell.editButton.isHidden = true
            cell.deleteButton.isHidden = true
            cell.deleteButton.addTarget(self, action: #selector(deleteAction(button:)), for: .touchUpInside)
            let checkIndex = self.checkIsRadioSelect.index(of: indexPath.row)
            if(checkIndex != nil){
                cell.radioButton.isSelected = true
                cell.editButton.isHidden = false
                cell.deleteButton.isHidden = false
            }
            else
            {
                cell.radioButton.isSelected = false
                cell.editButton.isHidden = true
                cell.deleteButton.isHidden = true
            }
            return cell
        }

And image for this is shown below

1 个答案:

答案 0 :(得分:0)

在删除方法中添加两行。

func deleteAction(button: UIButton) {
    let buttonPosition = button.convert(CGPoint(), to: tableDetails)
    let index = tableDetails.indexPathForRow(at: buttonPosition)
    self.tableDetails.beginUpdates()
    shippingArray.remove(at:(index?.row)!)
    self.tableDetails.deleteRows(at: [index!], with: .top)
    self.tableDetails.endUpdates()
    tableDetails.tableFooterView?.isHidden = true
    self.addressSelected = false

    **let checkIndex = self.checkIsRadioSelect.index(of: button.tag)
    self.checkIsRadioSelect.remove(at:checkIndex)**

    self.tableDetails.reloadData()
}