在 swift 的工具栏中添加一个 UITableView 编辑按钮
Add a UITableView Edit button to the toolbar in swift
我有一个 UIControllerView
,其中包含 2 个 table,每个都有一个单独的控制器。 table 之一包含可以删除的项目。
默认情况下,可以将编辑按钮添加到 导航栏,将以下内容添加到 viewDidLoad()
中的 UITableViewController
:
self.navigationItem.leftBarButtonItem = self.editButtonItem()
但我需要底部 工具栏 中的这个编辑按钮。我试过这个:
创建了一个从工具栏按钮到 UIViewController
文件的出口,如下所示:
class foo: UIViewController{
@IBOutlet weak var deleteUserCategoriesButton: UIBarButtonItem!
...
override func viewDidLoad() {
super.viewDidLoad()
toobarButton = list2TableController.editButtonItem()
// list2TableController is the UITableViewController of the table of which items are deletable
}
...
}
这不起作用。在 swift 中执行此操作的正确方法是什么?
从 toolbarButton 创建一个 IBAction。在操作中调用 tableViews setEditing(_ editing: Bool, animated animate: Bool)
方法。
我有一个 UIControllerView
,其中包含 2 个 table,每个都有一个单独的控制器。 table 之一包含可以删除的项目。
默认情况下,可以将编辑按钮添加到 导航栏,将以下内容添加到 viewDidLoad()
中的 UITableViewController
:
self.navigationItem.leftBarButtonItem = self.editButtonItem()
但我需要底部 工具栏 中的这个编辑按钮。我试过这个:
创建了一个从工具栏按钮到 UIViewController
文件的出口,如下所示:
class foo: UIViewController{
@IBOutlet weak var deleteUserCategoriesButton: UIBarButtonItem!
...
override func viewDidLoad() {
super.viewDidLoad()
toobarButton = list2TableController.editButtonItem()
// list2TableController is the UITableViewController of the table of which items are deletable
}
...
}
这不起作用。在 swift 中执行此操作的正确方法是什么?
从 toolbarButton 创建一个 IBAction。在操作中调用 tableViews setEditing(_ editing: Bool, animated animate: Bool)
方法。