【发布时间】:2016-07-30 21:56:54
【问题描述】:
我有一个 RootViewController,它嵌入了一个包含表格的容器:
我希望 RootViewController 左上角的垃圾桶图标启用嵌入式表格视图的编辑模式。我希望它们显示为复选框,以便我可以一次选择多行,然后按“删除”删除所有选定的行。
我该怎么做?
【问题讨论】:
标签: swift
我有一个 RootViewController,它嵌入了一个包含表格的容器:
我希望 RootViewController 左上角的垃圾桶图标启用嵌入式表格视图的编辑模式。我希望它们显示为复选框,以便我可以一次选择多行,然后按“删除”删除所有选定的行。
我该怎么做?
【问题讨论】:
标签: swift
希望你的班级已经像这样符合UITableViewDelegate:
class MyViewController: UIViewController, UITableViewDelegate
在viewDidLoad() 中,您需要:
myTable.delegate = self
然后您可以将垃圾桶图标连接到将表格设置为编辑模式的 IBAction:
@IBAction func myTableSetEditing(sender: AnyObject) {
myTable.setEditing(true, animated: true)
}
然后,正如我们在此处的答案中看到的:Select multiple rows in tableview and tick the selected ones,在viewDidLoad() 中输入:
self.tableView.allowsMultipleSelection = true
并获得您的复选标记,实施:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = UITableViewCellAccessoryType.Checkmark
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
tableView.cellForRowAtIndexPath(indexPath)?.accessoryType = UITableViewCellAccessoryType.None
}
【讨论】:
myTable 吗?