[英]how to remove index path for the radio button in table view cell?
在啟用單選按鈕后,這里有一個單選按鈕,然后在選擇“刪除”后將顯示刪除和編輯按鈕,特定單元正在刪除,但上一行單選按鈕正在啟用,如何避免這種幫助?
這是代碼
@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
}
在刪除方法中添加兩行。
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()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.