Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 静态单元格中的复选框_Ios_Swift_Uitableview_Checkbox_Uiswitch - Fatal编程技术网

Ios 静态单元格中的复选框

Ios 静态单元格中的复选框,ios,swift,uitableview,checkbox,uiswitch,Ios,Swift,Uitableview,Checkbox,Uiswitch,我是Swift新手,我开始学习表格中的复选框,但我的表格工作正常 I使用静态单元格: 我的代码: var flagCell : Bool = false override func viewDidLoad() { super.viewDidLoad() tableView.separatorInset = .zero tableView.layoutMargins = .zero let nav = self.navigationController?.

我是Swift新手,我开始学习表格中的复选框,但我的表格工作正常 I使用静态单元格:

我的代码:

 var flagCell : Bool = false

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.separatorInset = .zero
    tableView.layoutMargins = .zero

    let nav = self.navigationController?.navigationBar
    nav?.tintColor = UIColor(red: 16.0, green: 18.0, blue: 34.0, alpha: 1.0)
    nav?.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if let cell = tableView.cellForRow(at: indexPath) {
        tableView.deselectRow(at: indexPath, animated: true)

        if flagCell  == false{
            cell.accessoryType = .checkmark
            flagCell = true
        }else {
            cell.accessoryType = .none
            flagCell = false
        }
    }
}
马克熬过了一段时间

它如何解决

我还想用si on做UIS,所有单元格上都会出现复选标记

我如何实现它


将此代码放入
cellForRowAtIndexPath

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellID")
    if flagCell  == false {
      cell.accessoryType = .checkmark
    } else {
      cell.accessoryType = .none
    }
  }
并在录音后重新加载

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
   flagCell = !flagCell
   tableView.reloadData()
}
也可以使用其他方法更新单元格:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
       flagCell = !flagCell
       tableView.reloadRows(at: [indexPath], with: .automatic)
    }

“但我的表工作正常”
或工作不正常?@Mr.Bista标记只有在我单击两次时才会消失@kerl两次@kerlааааСааааааа是,因为第一次单击flag的值为true,第二次单击else块时以true条件执行。并且取消选中标记。@Tushar Sharma我不知道如何修复它如何修复?@kerlа到目前为止,我想您的解决方案是-:我有一个错误:由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将标识符为cellID的单元格出列-必须为标识符注册nib或类,或在情节提要中连接原型单元格”@kerköааа尝试使用
let cell=tableView.cellForRow(at:indexPath)
代码获取单元格,或者在
Interface builder
中为所有静态单元格添加标识符,并将其用于将单元格出列