抱歉,我是全新的 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