在范围内找不到类型“ViewController”。不知道怎么办

问题描述 投票:0回答:0

我发现不能使用 vc 将数据从一个视图控制器传输到另一个,警告错误是

'Cannot find type 'ViewController' in scope'

在我的第二个视图控制器中我有

          func switchDidChangeValue(_ value: Bool) {
          let storyboard = UIStoryboard(name: "KeyboardStoryboard", bundle: nil)
          let secondVC = storyboard.instantiateViewController(withIdentifier: "SecondVC") as! KeyboardViewController
          let firstVC = self.navigationController?.viewControllers.first as! ViewController
          firstVC.delegate = secondVC
          self.navigationController?.pushViewController(secondVC, animated: true)
      }

在我的第一个视图控制器中

protocol SwitchDelegate: AnyObject {
    func switchDidChangeValue(_ value: Bool)
}
class ViewController: UIViewController {
    @IBAction func AutoSpacePressed(_ sender: UISwitch) {

        delegate?.switchDidChangeValue(sender.isOn)
}
}
ios swift viewcontroller
© www.soinside.com 2019 - 2024. All rights reserved.