-4

I'm hoping i'm missing something pretty simple here, but I can't seem to get my head around it!

I am reading a QR code and pushing to my next view controller once the QR code has been read:

if metadataObj.stringValue != nil {
            let qrData = metadataObj.stringValue

            let segueViewController = self.storyboard?.instantiateViewControllerWithIdentifier("confirmScan") as? ScanConfirm
            self.navigationController?.pushViewController(segueViewController!, animated: true)
            captureSession?.stopRunning() }

I would then like to pass the data found in the QR code and show it in my next view's label. I have tried using prepareForSegue but this doesn't seem to be working.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let NextViewController : ScanConfirm = segue.destinationViewController as! ScanConfirm
    NextViewController.newLabel.text = qrData
}

Any help would be HUGELY appreciated!

Thanks

evorg88
  • 215
  • 2
  • 12

1 Answers1

0

create a property in ScanConform class

class ScanConform: UIViewController {
var scanData:String?

you can place below code viewdidload or viewwillapper

override func viewDidLoad() {
        super.viewDidLoad()
guard let displayData = scanData else { return }
newLabel.text = displayData
     }
}

While Setting Data Do Like this

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()
 }
Ramkumar chintala
  • 958
  • 11
  • 24