Because of UI elements, I created View Controller with a TableView inside. But I can't enable editing mode. I tried several methods without Solution. But with using TableView Controller there are no problems.
What I tried:
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
}
}
Where can be the problem?
You forgot to put the table view in editing mode:
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
self.tableView.setEditing(editing, animated: animated)
}
I'm assuming you have a tableView
property. Adjust as needed.
Some other things you may want to do to emulate a UITableViewController
:
viewWillAppear
you should deselect the currently selected row in the table view.viewDidAppear
you should flash the scrollbars of the table view.