2016-08-31 65 views
-3

我有下面的代码和它应该做的是这样的: 当相机检测到QR码时,它应该通过标识符SendDataSegue打开我的DetailViewController。问题是,当检测到QR码时,什么都没有发生?有人能帮我一下吗?这是代码的底部,我正在尝试使用prepareforsegue。用qr代码激活prepareforsegue

func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) { 
 
     
 
     // Check if the metadataObjects array is not nil and it contains at least one object. 
 
     if metadataObjects == nil || metadataObjects.count == 0 { 
 
      qrCodeFrameView?.frame = CGRectZero 
 
      messageLabel.text = "No barcode/QR code is detected" 
 
      return 
 
     } 
 
     
 
     // Get the metadata object. 
 
     let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject 
 
     
 
     // Here we use filter method to check if the type of metadataObj is supported 
 
     // Instead of hardcoding the AVMetadataObjectTypeQRCode, we check if the type 
 
     // can be found in the array of supported bar codes. 
 
     if supportedBarCodes.contains(metadataObj.type) { 
 
//  if metadataObj.type == AVMetadataObjectTypeQRCode { 
 
      // If the found metadata is equal to the QR code metadata then update the status label's text and set the bounds 
 
      let barCodeObject = videoPreviewLayer?.transformedMetadataObjectForMetadataObject(metadataObj) 
 
      qrCodeFrameView?.frame = barCodeObject!.bounds 
 
      
 
      if metadataObj.stringValue != nil { 
 
       
 
       
 
       func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { 
 
        if (segue.identifier == "SendDataSegue") { 
 
         // pass data to next view 
 
        } 
 
       } 
 
       
 
       
 
       
 
       
 
      } 
 
     } 
 
    }

+0

您不要在那里声明该方法。你只需要'self.performSegue(“SendDataSegue”,sender:nil)''。 – Larme

+0

但是如果我有一个标签,在我的DetailViewController上应该更改为QR代码所说的内容? –

+0

当你使用你的代码@Larme它说:类型ViewController的值没有成员preformSegue –

回答

0

这段代码帮助我:

dispatch_async(dispatch_get_main_queue()){ 
       self.performSegueWithIdentifier("SendDataSegue", sender:self) 


      } 

有谁知道如何通过传递数据?我可以通过一个正常的func prepareforsegue传递数据,但是我怎么通过这个来做到这一点?