我正在尝试创建一个条件语句,它根据 tableView 是否有任何复选标记附件来执行操作。
目前,我有以下代码检查记录是否被选中,但我想检查 tableView 中的任何行中是否存在复选标记附件,这样的事情可以验证吗?
查看行是否被选中的代码:
if structure.isEmpty ||
(tableView.indexPathsForSelectedRows != nil &&
!tableView.indexPathsForSelectedRows!.isEmpty) {
//Do this...
} else {
//Do this...
}
structure
定义为 var structure = [JSONStructure]()
JSONStructure 是填充 tableView 的 JSON 数据的结构。
最佳答案
我建议您添加一个数组来跟踪带有复选标记附件的行,因此当您添加一个复选标记时,您也将该行的 indexPath 添加到数组中,当您删除复选标记时也是如此
let checkedCells = [IndexPath]()
现在你可以像这样添加你的声明
if structure.isEmpty || !checkedCells.isEmpty {
//Do this...
} else {
//Do this...
}
关于swift - 根据tableView中的附件创建条件语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57698969/