Swift 单击具有特定标题的单元格时,取消选中所有附件复选标记
我有一个tableView,它显示了一个可选选项列表。其中一个单元格标题为“其他”,另一个单元格标题为“以上无” 当我单击“其他”时,我希望在单元格中显示一个文本框并接受文本。从文本框返回后,单元格标题应替换为输入的文本 当我点击“以上无一个”时,我希望所有的accessoryType单元格都是.NoneSwift 单击具有特定标题的单元格时,取消选中所有附件复选标记,swift,uitableview,Swift,Uitableview,我有一个tableView,它显示了一个可选选项列表。其中一个单元格标题为“其他”,另一个单元格标题为“以上无” 当我单击“其他”时,我希望在单元格中显示一个文本框并接受文本。从文本框返回后,单元格标题应替换为输入的文本 当我点击“以上无一个”时,我希望所有的accessoryType单元格都是.None struct SelectedOptions : Codable { var title : String = "" var isChecked : Bool = false
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()
}
}
struct SelectedOptions:Codable{
变量标题:String=“”
已检查变量:Bool=false
}
var options=SelectedOptions()
让cell=tableView.cellForRow(at:indexPath)
//如果选择了选项列表[indexPath.row]。isChecked==true{
if((单元格?.textlab?.text==“其他”)&&selectedOptionsList[indexPath.row].isChecked==true){
//1.创建警报控制器。
let alert=UIAlertController(标题:,消息:“请输入其他条件。”,首选样式:。警报)
//2.添加文本字段。您可以根据需要进行配置。
alert.addTextField{(textField)位于
//textField.text=“一些默认文本”
}
//3.从文本字段中获取值,并在用户单击“确定”时打印。
addAction(UIAlertAction,标题:“OK”,样式:。默认值,处理程序:{[weak alert](41;)in
让textField=alert?.textFields![0]//强制展开,因为我们知道它存在。
self.selectedOptionsList[34]。title=textField?.text???“其他”
tableView.reloadData()
打印(“文本字段:\(文本字段?.Text)”)
}))
//4.发出警报。
self.present(警报、动画:true、完成:nil)
}else if((cell?.textlab?.text==“目前这些条件都不适用于我。”)&&selectedOptionsList[indexPath.row].isChecked==true){
对于SelectedOptions列表[0]中的var条件。您提到您有一个可选选项列表。若要确认(请不要回复评论,请编辑您的问题以包含附加信息),您的表视图中只有两个可选选项/单元格?请包括您的cellForRow方法,以便我们更好地理解。另外,您能否提供错误/正确行为的图像?