在Swift中将数据传递到目标VC(带框架)?

时间:2022-11-02 15:38:40

I'm writing an application that takes data from a QR code scanner. I am just implementing the basics, and have a second view controller that is triggered when a new QR code is detected. The following code is in a custom view controller from RSBarcodes and implemented using CocoaPods.
It won't compile with the error

我正在编写一个从QR代码扫描程序获取数据的应用程序。我只是实现了基础知识,并且在检测到新的QR代码时会触发第二个视图控制器。以下代码位于RSBarcodes的自定义视图控制器中,并使用CocoaPods实现。它不会与错误一起编译

"Use of undeclared type SecondViewController".

“使用未声明的类型SecondViewController”。

I tried making my SecondViewController public, restarting XCode, and nothing has worked. Any help is appreciated. Thank you!

我尝试将我的SecondViewController公开,重新启动XCode,但没有任何工作。任何帮助表示赞赏。谢谢!

override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let destinationVC = segue.destinationViewController as! SecondViewController
    destinationVC.label = "test"  

}

SOLUTION:

Added to "Copy Bundle Resources" and then my VC was immediately recognized by the compiler.

添加到“复制捆绑资源”,然后我的VC立即被编译器识别。

2 个解决方案

#1


SOLUTION:

Added to "Copy Bundle Resources" and then my VC was immediately recognized by the compiler.

添加到“复制捆绑资源”,然后我的VC立即被编译器识别。

#2


First you have to verify which segue you're pushing to by checking the segue identifier name. Then you have to check if you can even create the destinationVC variable, and then if you can unwrap it using '?' instead of '!'.

首先,您必须通过检查segue标识符名称来验证您要推送的segue。然后你必须检查你是否甚至可以创建destinationVC变量,然后你可以使用'?'来解开它代替 '!'。

override public func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?) {
    if segue.identifier == "nameOfMySegue" {
        if let destinationVC = segue.destinationViewController as? SecondViewController {
            destinationVC.label = "test"
        }
    }
}

#1


SOLUTION:

Added to "Copy Bundle Resources" and then my VC was immediately recognized by the compiler.

添加到“复制捆绑资源”,然后我的VC立即被编译器识别。

#2


First you have to verify which segue you're pushing to by checking the segue identifier name. Then you have to check if you can even create the destinationVC variable, and then if you can unwrap it using '?' instead of '!'.

首先,您必须通过检查segue标识符名称来验证您要推送的segue。然后你必须检查你是否甚至可以创建destinationVC变量,然后你可以使用'?'来解开它代替 '!'。

override public func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?) {
    if segue.identifier == "nameOfMySegue" {
        if let destinationVC = segue.destinationViewController as? SecondViewController {
            destinationVC.label = "test"
        }
    }
}