Ios UIAlertController在警报操作时移动到另一个控制器-Swift

Ios UIAlertController在警报操作时移动到另一个控制器-Swift,ios,swift,uiviewcontroller,uialertcontroller,uialertaction,Ios,Swift,Uiviewcontroller,Uialertcontroller,Uialertaction,我正在尝试在警报视图操作中移动到另一个控制器。它正在按预期移动到下一个控制器,但一旦移动到另一个控制器,它将再次显示相同的警报。请检查下面的代码 func decode(decodedURL: String) { let alertController = UIAlertController(title: "", message: "Confirm", preferredStyle: .alert) let viewController = self.storyboard?.i

我正在尝试在警报视图操作中移动到另一个控制器。它正在按预期移动到下一个控制器,但一旦移动到另一个控制器,它将再次显示相同的警报。请检查下面的代码

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

        }
    }
}
委托功能是

AVCaptureMataOutputObjectsDelegate

。它将继续被调用,直到您的captureSession处于活动状态

所以,当您导航到下一个屏幕时,只需停止captureSession

captureSession?.stopRunning() 
captureSession = nil
委托功能是

AVCaptureMataOutputObjectsDelegate

。它将继续被调用,直到您的captureSession处于活动状态

所以,当您导航到下一个屏幕时,只需停止captureSession

captureSession?.stopRunning() 
captureSession = nil

我有一个带有“确定”和“取消”按钮的alertview。此代码在当前viewController的哪个功能中执行?@Mac_Play,如果我没有错的话。metadataOutput函数可以多次调用。直到调用captureSession?.stopRunning()captureSession=nilmetadataOutput是AvCaptureMataOutputObjectsDelegate的委托函数。它将继续被调用,直到您停止它。是的,如果(//必需的扫描完成){captureSession?.stopRunning()captureSession=nil}在MetadataOutput中,我有一个带有“确定”和“取消”按钮的alertview。在当前viewController的哪个函数中执行此代码?@Mac_Play,如果我没有错的话。metadataOutput函数可以多次调用。直到调用captureSession?.stopRunning()captureSession=nilmetadataOutput是AvCaptureMataOutputObjectsDelegate的委托函数。它将继续被调用,直到您停止它。是的,如果(//必需的扫描完成){captureSession?.stopRunning()captureSession=nil}在MetadataOutputCand中无法将类型为“AVMetadataFaceObject”(0x1b245bd28)的值强制转换为“AvMetadataMachinerAdableCodeObject”(0x1b245be68),则可以这样写。经常出现此错误,您知道吗?无法将类型为“AVMetadataFaceObject”(0x1b245bd28)的值强制转换为“AVMetadataMachineReadableCodeObject”(0x1b245be68)。经常犯这样的错误,知道吗?