我想通过复选标记删除未选定行中的数据。现在我可以将字符串附加到已检查的数组中。但我想从数组中删除哪些未经检查的数据。如何从数组中删除未经检查的数据?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if(tableView == self.tableView_1) {
if(tableView_1.cellForRow(at: indexPath)?.accessoryType == UITableViewCellAccessoryType.none) {
tableView_1.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.checkmark
checkedItemsForGender.append(cinsiyet[indexPath.row])
}
else{
tableView_1.cellForRow(at: indexPath)?.accessoryType = UITableViewCellAccessoryType.none
checkedItemsForGender.remove(at: cinsiyet[indexPath.row]) // ??? ERROR
}
}
最佳答案
你应该使用这个:
if let index = checkedItemForGender.index(of: cinsiyet[indexPath.row]) {
checkedItemsForGender.remove(at: index)
}
关于arrays - 在 Swift 中从数组中选定的复选标记中删除字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50116685/