Swift / 在视图控制器中启用编辑模式
Posted
技术标签:
【中文标题】Swift / 在视图控制器中启用编辑模式【英文标题】:Swift / Enable Editing Mode in View Controller 【发布时间】:2015-06-06 22:28:36 【问题描述】:因为 UI 元素,我创建了 View Controller 里面有一个 TableView。 但我无法启用编辑模式。我尝试了几种没有解决方案的方法。 但是使用 TableView Controller 没有问题。
我尝试了什么:
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
问题可能出在哪里?
【问题讨论】:
但这是针对 tableview Controller 而不是 viewcontroller 【参考方案1】:您忘记将表格视图置于编辑模式:
override func setEditing(editing: Bool, animated: Bool)
super.setEditing(editing, animated: animated)
self.tableView.setEditing(editing, animated: animated)
我假设您有一个 tableView
属性。根据需要进行调整。
您可能想要做的其他一些事情来模拟UITableViewController
:
-
在
viewWillAppear
中,您应该取消选择表格视图中当前选定的行。
在viewDidAppear
中,您应该闪烁表格视图的滚动条。
【讨论】:
以上是关于Swift / 在视图控制器中启用编辑模式的主要内容,如果未能解决你的问题,请参考以下文章