[英]Uncheck TableView all TableView Selections in Swift4
我已经搜索过,还没有找到解决方案:
UIViewController
)上。 是否可以使用协议和委托,还是需要单身人士? 我希望它在单击按钮时更新。 几年前,我在这里看到了Dejan Skledar的回答: 点击时可以打开和关闭UITableViewCell复选标记,而名为resetChecks()
的函数似乎是我想要的,但是我很难让Swift编写的代码起作用。 当我运行它时,它实际上并没有进入该方法,然后在调用该方法时,它崩溃并显示“意外找到nil”。 请,有人可以提供一些建议吗? 谢谢。 这是我写的:
func removeChecks() {
for i in 0...grainTableView.numberOfSections - 1 {
for j in 0...grainTableView.numberOfRows(inSection: i) - 1 {
if let cell = tableView(grainTableView, cellForRowAt: [i,j]) as? UITableViewCell {
cell.accessoryType == .none
}
}
}
}
当您展示currentVC时,从preVC发送对象
class currentVC:UIViewController {
var delegate:PreVC?
func removeChecks() {
if let grainTableView = delegate?.tableView {
for i in 0...grainTableView.numberOfSections - 1 {
for j in 0...grainTableView.numberOfRows(inSection: i) - 1 {
if let cell = tableView(grainTableView, cellForRowAt: [i,j]) as? UITableViewCell {
cell.accessoryType == .none
}
}
}
}
}
//
func removeChecks() {
if let grainTableView = delegate?.tableView {
delegate?.shouldClear = true
grainTableView.reloadData()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.