我有類firstViewController在這個函數產生的itemid訪問常數從另一個視圖控制器
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from 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 = CGRect.zero
messageLabel.text = "No QR/barcode is detected"
return
}
//Get metadata object
let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
if supportedCodeTypes.contains(metadataObj.type) {
//if the found metadata is equal to the QR code metadata then update the status label's text and set the the bounds
let barCodeObject = videoPreviewLayer?.transformedMetadataObject(for: metadataObj)
qrCodeFrameView?.frame = barCodeObject!.bounds
if metadataObj.stringValue != nil {
messageLabel.text = metadataObj.stringValue
let itemID = metadataObj.stringValue
print(itemID)
}
}
}
我想打電話給ITEMID在其他的viewController稱爲secondViewController。如何從secondViewController中的firstViewController調用itemID?
謝謝,我正在做所有的編程。在FirstViewController中究竟應該聲明代碼,我似乎有這個問題讓secondViewConttoller = SecondViewController() secondViewController.itemIdForSVC = self.itemID self.navigationController?.pushViewController(secondViewConttoller,animated:true) –
您應該添加這段代碼從你想要去的下一個第二頁開始,即onButtonTapped事件。 –