swift Present Modally Segue exc bad instruction

时间:2017-03-18 22:13:00

标签: ios swift segue

所以我只是学习Swift的基础知识。我有一个项目的表格视图,当点击一个项目时,我想显示一个显示该特定项目的详细信息的视图。我有下面的代码,我正在尝试实现这一点,但是,我收到了错误的指令运行时错误。知道我哪里错了吗?谢谢!

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.

    super.prepare(for: segue,sender: sender)

    switch(segue.identifier ?? "") {
    //the add item button is pressed
    case "AddItem":
        os_log("Adding a new donation.", log: OSLog.default, type: .debug)

    //an existing item is pressed
    case "ShowDetailDrill":

        guard let itemViewController = segue.destination as? ItemViewController else {
            fatalError("Unexpected destination: \(segue.destination)")
        }

        guard let selectedDonationItemCell = sender as? DonationItemCell else {
            fatalError("Unexpected sender: \(sender)")
        }

        guard let indexPath = tableView.indexPath(for: selectedDonationItemCell) else {
            fatalError("The selected cell is not being displayed by the table")
        }

        let selectedDonation = donatedItems.getItem(index: indexPath.row)

        //TODO: load this to SubmissionVC
        itemViewController.donatedItem = selectedDonation

    default:
        fatalError("Unexpected Segue Identifier; \(segue.identifier)")
    }

}

enter image description here

更新

我忘了提到它在这里打破了

enter image description here

更新2:好的,所以我删除了导航控制器并将segue从“当前模态”更改为“显示”。它直接从单元格转到项目控制器。现在一切都有效,尽管我仍然对它为何不使用导航控制器感到困惑。如果有人能够解释原因,我会将其标记为答案。

1 个答案:

答案 0 :(得分:0)

是来自tableviewcell的ShowDetailDrill segue的起源吗?如果是,请尝试删除它,然后从tableviewcontroller到ItemViewController创建一个新的segue。