[英]Unselect all accessory checkmarks when clicked on a cell with specific title
我有一个 tableView 显示可选选项列表。 其中一个单元格标题是“Other”,另一个是“None of above”。
当我单击“其他”时,我希望在单元格中显示一个文本框并接受文本。 从文本框返回后,单元格标题应替换为输入的文本。
当我点击“以上都不是”时,我希望所有的单元格的附件类型都是.none。
struct SelectedOptions : Codable {
var title : String = ""
var isChecked : Bool = false
}
var options = SelectedOptions()
let cell = tableView.cellForRow(at: indexPath)
// if selectedOptionsList[indexPath.row].isChecked == true {
if ((cell?.textLabel?.text == "Other") && selectedOptionsList[indexPath.row].isChecked == true) {
//1. Create the alert controller.
let alert = UIAlertController(title: "", message: "Please enter other condition.", preferredStyle: .alert)
//2. Add the text field. You can configure it however you need.
alert.addTextField { (textField) in
//textField.text = "Some default text"
}
// 3. Grab the value from the text field, and print it when the user clicks OK.
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { [weak alert] (_) in
let textField = alert?.textFields![0] // Force unwrapping because we know it exists.
self.selectedOptionsList[34].title = textField?.text ?? "Other"
tableView.reloadData()
print("Text field: \(textField?.text)")
}))
// 4. Present the alert.
self.present(alert, animated: true, completion: nil)
} else if((cell?.textLabel?.text == "None of these conditions apply to me at this time.") && selectedOptionsList[indexPath.row].isChecked == true){
for var condition in selectedOptionsList[0..<35]{
condition.isChecked = false
tableView.reloadData()
}
}
我在警报中显示一个文本字段以获取文本输入并在索引路径中替换该文本。
但是,对于“以上都不是”,即使我正在更新所有标题的 isChecked 条件,但以上都不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.