在View Controller中启用/启用编辑模式

由于UI元素,我创build了一个TableView里面的视图控制器。 但是我无法启用编辑模式。 我尝试了几种不使用Solution的方法。 但是使用TableView控制器没有问题。

我试过的:

override func viewDidLoad() { self.navigationItem.rightBarButtonItem = self.editButtonItem() } override func setEditing(editing: Bool, animated: Bool) { super.setEditing(editing, animated: animated) } func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { if (editingStyle == UITableViewCellEditingStyle.Delete) { // Action to delete data } } 

哪里可以解决问题?

你忘了把表视图编辑模式:

 override func setEditing(editing: Bool, animated: Bool) { super.setEditing(editing, animated: animated) self.tableView.setEditing(editing, animated: animated) } 

我假设你有一个tableView属性。 根据需要调整。

你可能想要做的其他一些事情来模拟一个UITableViewController

  1. viewWillAppear您应该取消select表视图中当前选定的行。
  2. viewDidAppear你应该刷新表视图的滚动条。