ios - 链接两个 ViewController 时出错

标签 ios swift xcode

我在我的 VC 中使用自定义圆形动画来连接到一个新的 VC,它工作正常,这就是代码

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

但是当我使用同一个 VC 上的另一个按钮转至另一个 VC 时,我收到一条错误消息,提示 Could not cast value of type 'I_Need.ReminderTableViewController' (0x1020e6e98) to 'I_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/

相关文章:

ios - 弹出 VC 时 Google 登录按钮不起作用

ios - Xcode UI 测试 - UITableView 部分

ios - TextField 在编辑 Swift 4 时消失

ios - 单击 TextView 中的电话号码或电子邮件地址时出错

ios - Firebase 架构 x86_64 的 undefined symbol

objective-c - 如何将多个 NSMutableDictionaries 中的键更改为当前值的 -1?

swift - 我该如何修复这个 "Expected ' ,' 分隔符? swift

ios - iOS 10.3 中的备用图标

xcode - 执行某项操作 "x"秒,然后执行其他操作

ios - Xcode 11 (11A420a) 使用 Command-Click 声明时不显示 "Embed in H/VStack"菜单项