我有以下代码,它应该做什么,是这样的: 当相机检测到QR码时,它应该打开我的DetailViewController,通过标识符:SendDataSegue。问题是,当检测到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 :(得分:0)
This piece of code helped me:
dispatch_async(dispatch_get_main_queue()){
self.performSegueWithIdentifier("SendDataSegue", sender:self)
}
Does anyone know how to pass data through that? I can pass data through a normal func prepareforsegue, but how do I do it through this?