简体   繁体   English

编辑栏按钮无法正常工作

[英]Edit bar button doesn't work as intended

In my table view controller's viewDidLoad: method I have the standard line self.navigationItem.leftBarButtonItem = self.editBarButtonItem() to add the Edit bar button. 在我的表视图控制器的viewDidLoad:方法中,我具有标准行self.navigationItem.leftBarButtonItem = self.editBarButtonItem()以添加编辑栏按钮。

When my table view controller is a subclass of UITableViewController (and thus has the table view as its view property), the Edit button works normally and triggers a change of table view's editing state. 当我的表视图控制器是UITableViewController的子类(因此将表视图作为其view属性)时,“编辑”按钮将正常工作并触发表视图的editing状态更改。

But after I had rewritten my table view controller so it now subclasses UIViewController (implementing UITableViewDataSource and UITableViewDelegate protocols), the Edit button has stopped working. 但是,在我重写了表格视图控制器之后,现在它UIViewController子类(实现UITableViewDataSourceUITableViewDelegate协议),“编辑”按钮已停止工作。 It still switches between Edit and Done, but no longer changes table view's editing state. 它仍然在“编辑”和“完成”之间切换,但不再更改表视图的editing状态。

How to fix that? 如何解决? Should I implement setEditing: animated: method in my view controller? 我应该在视图控制器中实现setEditing: animated:方法吗? If yes, could you post some sample code? 如果是,您可以张贴一些示例代码吗?

It was simple. 很简单。 I just had to call super and update table view's editing state. 我只需要调用super并更新表视图的editing状态。

override func setEditing(editing: Bool, animated: Bool) {

    super.setEditing(editing, animated: animated)
    tableView.setEditing(editing, animated: animated)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM