首页 文章

使用editActions编辑UITableView行并执行Segue?

提问于
浏览
0

我尝试在TableView中添加一个滑动来编辑选项 . 如果用户按下编辑,则应打开新视图 .

但是我总是在func“editActionsForRowAt”中遇到错误“if segue.identifier ==”ItemDetailsVS {“”“:致命错误:在展开Optional值时意外发现nil

segue在Storyboard中具有正确的名称 . 有任何想法吗?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "ItemDetailsVC" {
        if let destination = segue.destination as? ItemDetailsViewController {
            if let item = sender as? Item2 {
                destination.itemToEdit = item
            }
        }
    }
}

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let edit = UITableViewRowAction(style: .normal, title: "Edit"){ (action, indexPath) in

        var segue: UIStoryboardSegue!

        if segue.identifier == "ItemDetailsVC" {
            if let objects = self.controller.fetchedObjects , objects.count > 0 {
                let item = objects[indexPath.row]
                self.performSegue(withIdentifier: "ItemDetailsVC", sender: item)
                }
            }
        }
    return [edit]

}

1 回答

相关问题