我在我的VC中使用了一个自定义的循环动画来切换到一个新的VC,它运行良好,这是代码

 override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
    let secondVC = segue.destination as! SecondViewController
    secondVC.transitioningDelegate = self
    secondVC.modalPresentationStyle = .custom
}

但是,当我使用同一个VC上的另一个按钮切换到另一个VC时,出现一个错误,说无法将“I\u Need.ReminderTableViewController”(0x1020e6e98)类型的值转换为“I\u Need.SecondViewController”(0x1020e6a08)。

最佳答案

您需要执行if let而不是let,因为您的另一个VC不是SecondViewController类型:

if let secondVC = segue.destination as? SecondViewController{
    secondVC.transitioningDelegate = self
    secondVC.modalPresentationStyle = .custom
}

关于ios - 链接两个ViewController时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42770276/

10-13 09:27