【发布时间】:2018-08-28 08:30:55
【问题描述】:
我正在尝试在警报视图操作中移动到另一个控制器。它正在按预期移动到下一个控制器,但是一旦它移动到另一个控制器,它就会再次显示相同的警报。请检查以下代码。
func decode(decodedURL: String) {
let alertController = UIAlertController(title: "", message: "Confirm", preferredStyle: .alert)
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "FormViewController") as? FormViewController
viewController?.fillData(dataDic: convertJsonStringToDictionary(jsonString: decodedURL))
let action1 = UIAlertAction(title: "Ok", style: .default) { (action) in
self.navigationController?.show(viewController!, sender: true)
}
let action2 = UIAlertAction(title: "Cancel", style: .cancel) { (action:UIAlertAction) in
print("You've pressed cancel");
}
alertController.addAction(action1)
alertController.addAction(action2)
self.present(alertController, animated: true, completion: nil)
}
在下面调用上面的方法
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
// Check if the metadataObjects array is not nil and it contains at least one object.
if metadataObjects.count == 0 {
qrCodeFrameView?.frame = CGRect.zero
messageLabel.text = "No code detected"
return
}
// Get the metadata object.
let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
if supportedCodeTypes.contains(metadataObj.type) {
// If the found metadata is equal to the QR code metadata (or barcode) then update the status label's text and set the bounds
let barCodeObject = videoPreviewLayer?.transformedMetadataObject(for: metadataObj)
qrCodeFrameView?.frame = barCodeObject!.bounds
if metadataObj.stringValue != nil {
decode(decodedURL: metadataObj.stringValue!)
messageLabel.text = metadataObj.stringValue
}
}
}
【问题讨论】:
-
我有一个带有确定和取消按钮的警报视图。
-
这段代码在当前viewController的哪个函数中执行?
-
@Mac_Play,如果我没记错的话。 metadataOutput 函数可以被多次调用。直到你调用了 captureSession?.stopRunning() captureSession = nil
-
metadataOutput 是 AVCaptureMetadataOutputObjectsDelegate 的委托函数。它会继续被调用,直到你停止它。
-
Yes , write like it, if (//required scan complete) { captureSession?.stopRunning() captureSession = nil } In side metaDataOutPut
标签: ios swift uiviewcontroller uialertcontroller uialertaction