【问题标题】:Swift / Enable Editing Mode in View ControllerSwift / 在视图控制器中启用编辑模式
【发布时间】: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

标签: ios swift uitableview uiviewcontroller edit


【解决方案1】:

您忘记将表格视图置于编辑模式:

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

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

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

  1. viewWillAppear 中,您应该取消选择表格视图中当前选定的行。
  2. viewDidAppear 中,您应该闪烁表格视图的滚动条。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多