从 UITableViewRowAction 触发 segue

Trigger segue from UITableViewRowAction

我已经阅读了很多关于这个问题的 SO 帖子,但不幸的是 none 的答案已经解决了我的问题。我有一个 UIViewController 里面有一个 TableView (我用这种方式设置了我想要的特定 UI 格式),现在如果用户向左滑动, deleteedit 按钮出现。我的 delete 操作工作正常,但到目前为止我尝试的 edit 的每次迭代都会给我一个 SIGABRT / terminating with uncaught exception of type NSException 错误。

我的 ViewController class 添加了 UIViewControllerUITableViewDataSourceUITableViewDelegate 协议。我的 tableView(editActionsForRowAt:) 函数的代码如下:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

    // Delete action
    let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Delete", handler: { (action, indexPath) -> Void in

        // Delete action code works fine

    })

    deleteAction.backgroundColor = GlobalPropertyKeys.LovalyticsRed

    let editAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Edit") {(action, indexPath) -> Void in

        // Will explain what I've tried so far below this

        print("Edit tapped.")
    }

    editAction.backgroundColor = GlobalPropertyKeys.LovalyticsBlue

    return [deleteAction, editAction]

}

我在 SO 上找到的所有答案都涉及在 IB 中创建从我的 ViewController 到目标屏幕的转场,为转场设置标识符,然后使用 performSegue(withIdentifier:sender:) 调用该转场的变体.

到目前为止我已经尝试过:

1.

    if let topController = UIApplication.topViewController() {
        topController.performSegue(withIdentifier: "segueToEditListItem", sender: topController)
    }

2.

    self.performSegue(withIdentifier: "segueToEditListItem", sender: self)

3.

    tableView.performSegue(withIdentifier: "segueToEditListItem", sender: tableView)
  1. 尝试从 TableView 而不是 ViewController
  2. 连接 segue

可能还有一些我删除的上述内容的变体,而不是将它们注释掉。每次单击 edit 时,我都会收到 SIGABRT 错误,我总是将其与错误连接 @IBOutlets 相关联。我检查以确保 segue 连接正确,当我删除任何提及的 segue 时,我的应用程序工作正常(edit 按钮打印 "Edit tapped."),所以这让我觉得我的有问题ViewController 无法识别我的 .swift 文件中的 segue。

我花了几个小时试图解决这个问题,但失败得很惨,所以任何帮助/建议都将不胜感激。

self.performSegue(withIdentifier: "Identifier", sender: self) 应该可以。
如果您的问题与 @IBOutlets 有关,您应该再次检查您的奥特莱斯。
如果您可以在有崩溃描述的地方写下您的控制台日志。