gpt4 book ai didi

ios - 从 UITableViewRowAction 触发 segue

转载 作者:行者123 更新时间:2023-11-28 06:00:54 25 4
gpt4 key购买 nike

我已经阅读了很多关于这个问题的 SO 帖子,但不幸的是,没有一个答案能解决我的问题。我有一个 UIViewController,里面有一个 TableView(我以这种方式设置它以获得我想要的特定 UI 格式),从现在开始,如果用户滑动到在左侧,出现了一个deleteedit 按钮。我的 delete 操作工作正常,但到目前为止我尝试的 edit 的每次迭代都给了我一个 SIGABRT/以 NSException 类型的未捕获异常终止 错误。

我的 ViewController 类添加了 UIViewControllerUITableViewDataSourceUITableViewDelegate 协议(protocol)。我的 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:发件人:)

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

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,您应该再次检查您的 Outlets。
如果您可以在有崩溃描述的地方写下您的控制台日志。

关于ios - 从 UITableViewRowAction 触发 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49781953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com