arrays - 如何在 [Int : Bool] 中获取 Int 的值?
问题描述
我试图从中获取 Int 的值,[Int : Bool]
以便我可以从 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)
}
推荐阅读
- sql - 仅更新内容以在字段中添加其他文本。SQL
- r - 有没有办法让用户在 R Shiny 应用程序中上传图像并将其呈现在可下载的降价报告中?
- perforce - 创建工作区时 Perforce 添加的“仓库”文件夹
- r - 如何使用 ggplot 绘制条形图
- c++ - 扫雷程序,意外输出
- google-sheets - 如何根据不同的文本字段进行计算?
- oracle - 如何在 apex oracle 应用程序中启用功能
- javascript - 浏览器中 JS、HTML、CSS 的执行顺序?
- php - Laravel 7 手动身份验证会话问题
- scala - Scala 是否可以使用特定版本的插件(plugins.sbt 中的 addSbtPlugin)?