ios - 无法确定从leadingSwipeActions 返回哪个发件人以准备继续
问题描述
抱歉,我是全新的 swift 和 IOS 开发人员,但我有一个表格视图,其中包含表格视图中的每个元素,我可以点击该项目以转到我的编辑屏幕,该屏幕确定表格单元格中的信息。我还想leadingSwipeActionsConfigurationForRowAt
调出一个编辑按钮,该按钮使用与点击单元格相同的 segue 方式进入编辑屏幕。问题是,prepare(for segue:)
由于leadingSwipeAction 的发送者,我处理tap segue 的声明一直失败。现在我真的很困惑我应该在我的leadingSwipeAction 中放置什么作为我的发件人。我尝试了一个UITableViewCell()
失败的守卫声明:
guard let ViewController = segue.destination as? ViewController else {
fatalError("Unexpected destination: \(segue.destination)")
}
作为一个 UIView() 然后我尝试发送一个taskCellTableViewCell
对象/类,它是我称为单个单元格的对象/类,但它返回了一个 nil/空单元格,该单元格在准备中失败了另一个保护语句。所以现在我对如何获取和发送执行leadingSwipeAction 的实际单元格感到困惑。我希望任何人都可以帮助我找出我需要返回以通过准备的正确发件人。谢谢
这是用于leadingSwipeAction 和准备的代码:
//leading swipe for editing code
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let edit = UIContextualAction(style: .normal, title: "Edit") { (contextualAction, view, actionPerformed: (Bool) -> ()) in
self.performSegue(withIdentifier: "showDetail", sender: UITableViewCell())
actionPerformed(true)
}
return UISwipeActionsConfiguration(actions: [edit])
}
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
super.prepare(for: segue, sender: sender)
switch(segue.identifier ?? "") {
case "addItem":
os_log("Adding a new task.", log: OSLog.default, type: .debug)
case "showDetail":
guard let ViewController = segue.destination as? ViewController else {
fatalError("Unexpected destination: \(segue.destination)")
}
guard let selectedTaskCell = sender as? taskCellTableViewCell else {
fatalError("Unexpected sender: \(sender)")
}
guard let indexPath = tableView.indexPath(for: selectedTaskCell) else {
fatalError("The selected cell is not being displayed by the table")
}
let selectedTask = tasks[indexPath.row]
ViewController.Task = selectedTask
default:
fatalError("Unexpected Segue Identifier; \(segue.identifier)")
}
}
再次尝试使用 showDetail segue 失败。
这里也是项目pastebin的完整代码的pastebin
解决方案
我不认为 atableViewCell
可以用作发件人,您是否无法将其设置为ViewController
您正在启动 segue,这应该可以。
推荐阅读
- .net-core - 关于 IDataErrorInfo 接口的几个问题
- kdb - 是否可以在 q 脚本中编写 k 代码?
- tomcat - 确定创建 tomcat 密钥库时使用的别名
- oracle - Oracle 一直显示“ORA-00907:缺少右括号”我做错了什么?
- python - 在自定义 IDE 中找不到 Python 导入 Camelot 模块
- angular - 页面刷新后如何保持在同一个角度页面?
- vba - 需要帮助实现对象构造函数
- c# - 在 Visual Studio 中创建新的 ASP.NET Web 应用程序时,所有这些模板是什么
- jquery - Css 输入错误样式未在 Edge 浏览器中正确显示
- ruby - 阻止 ActiveSupport::TaggedLogging 干扰结构化日志