我希望我在这里遗漏一些非常简单的东西,但我似乎无法理解它!
我正在读取QR码并在读取QR码后推送到我的下一个视图控制器:
if metadataObj.stringValue != nil {
let qrData = metadataObj.stringValue
let segueViewController = self.storyboard?.instantiateViewControllerWithIdentifier("confirmScan") as? ScanConfirm
self.navigationController?.pushViewController(segueViewController!, animated: true)
captureSession?.stopRunning() }
然后,我想传递二维码中的数据并将其显示在我的下一个视图标签中。我尝试过使用prepareForSegue,但这似乎并没有起作用。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let NextViewController : ScanConfirm = segue.destinationViewController as! ScanConfirm
NextViewController.newLabel.text = qrData
}
任何帮助都会非常感激!
由于
答案 0 :(得分:0)
在 ScanConform 类
中创建属性
class ScanConform: UIViewController {
var scanData:String?
您可以在代码viewdidload或viewwillapper
下面放置
override func viewDidLoad() {
super.viewDidLoad()
guard let displayData = scanData else { return }
newLabel.text = displayData
}
}
设置数据时这样做
if metadataObj.stringValue != nil {
let qrData = metadataObj.stringValue
let segueViewController = self.storyboard?.instantiateViewControllerWithIdentifier("confirmScan") as? ScanConfirm
segueViewController.scanData = grData
self.navigationController?.pushViewController(segueViewController!, animated: true)
captureSession?.stopRunning()
}