如何获取[Int : Bool]中Int的值?
How to get the value of Int in [Int : Bool]?
我正在尝试从 [Int : Bool]
获取 Int 的值,以便我可以从 tableView 中删除行值。
这是我的代码。
var checkmarks = [Int : Bool]()
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectedNamesIndex = indexPath.row
let cell = tableView.cellForRow(at: indexPath)
if let index = selectedNamesIndex {
if (cell?.accessoryType == .checkmark) {
cell!.accessoryType = .none
checkmarks[indexPath.row] = false
hasChecked = false
let indexPathTapped = tableView.indexPath(for: cell!)
let name = namelist[(indexPathTapped!.row)]
print(name, hasChecked)
selectedNamesToBroadcast.remove(at: checkmarks) // theres an error here: Cannot convert value of type '[Int : Bool]' to expected argument type 'Int'
} else {
cell!.accessoryType = .checkmark
checkmarks[indexPath.row] = true
hasChecked = true
let indexPathTapped = tableView.indexPath(for: cell!)
let name = namelist[(indexPathTapped!.row)]
print(name, hasChecked)
selectedNamesToBroadcast.append(name)
let selectedNamesToBroadcast = name
}
}
我希望能够取消选中颜色。这样当我更新数据库时,它就会被删除。
你可能想要
if let index = selectedNamesToBroadcast.index(of: name) {
selectedNamesToBroadcast.remove(at: index)
}
我正在尝试从 [Int : Bool]
获取 Int 的值,以便我可以从 tableView 中删除行值。
这是我的代码。
var checkmarks = [Int : Bool]()
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectedNamesIndex = indexPath.row
let cell = tableView.cellForRow(at: indexPath)
if let index = selectedNamesIndex {
if (cell?.accessoryType == .checkmark) {
cell!.accessoryType = .none
checkmarks[indexPath.row] = false
hasChecked = false
let indexPathTapped = tableView.indexPath(for: cell!)
let name = namelist[(indexPathTapped!.row)]
print(name, hasChecked)
selectedNamesToBroadcast.remove(at: checkmarks) // theres an error here: Cannot convert value of type '[Int : Bool]' to expected argument type 'Int'
} else {
cell!.accessoryType = .checkmark
checkmarks[indexPath.row] = true
hasChecked = true
let indexPathTapped = tableView.indexPath(for: cell!)
let name = namelist[(indexPathTapped!.row)]
print(name, hasChecked)
selectedNamesToBroadcast.append(name)
let selectedNamesToBroadcast = name
}
}
我希望能够取消选中颜色。这样当我更新数据库时,它就会被删除。
你可能想要
if let index = selectedNamesToBroadcast.index(of: name) {
selectedNamesToBroadcast.remove(at: index)
}