Swift /在View Controller中启用编辑模式 [英] Swift / Enable Editing Mode in View Controller
本文介绍了Swift /在View Controller中启用编辑模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于UI元素,我在里面用TableView创建了View Controller
。
但是我无法启用编辑模式。我尝试了几种没有Solution的方法。
但是使用TableView控制器没有问题。
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.
我尝试了什么:
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
}
}
哪里可以出问题?
推荐答案
你忘了放表格视图在编辑模式中:
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)
}
我假设你有 tableView
属性。根据需要进行调整。
I'm assuming you have a tableView
property. Adjust as needed.
您可能想要模仿 UITableViewController
:
- 在
viewWillAppear
中,您应取消选择表格视图中当前选定的行。 - 在
viewDidAppear
中,你应该刷新表格视图的滚动条。
- In
viewWillAppear
you should deselect the currently selected row in the table view. - In
viewDidAppear
you should flash the scrollbars of the table view.
这篇关于Swift /在View Controller中启用编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文