我目前在尝试将数据从QR码扫描仪控制器传递到视图控制器时遇到问题。这样做的原因是因为我在一个事件中会有30多个Qr代码,并且所有这些代码都将转换到相同的视图控制器但具有不同的标签/数据。
查看控制器
var myString:String = ""
@IBOutlet var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
label?.text = myString
}
QR扫描仪控制器
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let secondController = segue.destination as! Sample3Controller
if segue.identifier == "Segue1"
{
secondController.myString = "Welcome to Booth 1"
}
else if segue.identifier == "Segue2"
{
secondController.myString = "Welcome to Booth 2"
}
}
if metadataObj.stringValue == "Booth 1" //if qr code text is "Booth1"
{
captureSession?.stopRunning()
self.performSegue(withIdentifier: "Segue1", sender: self)
}
else if metadataObj.stringValue == "Booth 2" // if qr code text is "Booth2"
{
captureSession?.stopRunning()
self.performSegue(withIdentifier: "Segue2", sender: self)
}