迅速-警告:在演示过程中,尝试在*上演示*

问题描述 投票:2回答:1

由于此错误,我无法切换到另一个视图控制器。成功扫描QR码后,我想切换到另一个视图控制器。

2015-01-27 17:59:16.093 *[5416:1860144] Warning: Attempt to present <*.SuccessViewController: 0x144e38a20> on <*.MethodViewController: 0x144e2b960> whose view is not in the window hierarchy!

我的代码

@IBAction func btnQrCode(sender: AnyObject) { 
    reader.modalPresentationStyle = .FormSheet
    reader.delegate               = self

    reader.completionBlock = { (result: String?) in
    if result != nil {
        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

        let successViewController = storyBoard.instantiateViewControllerWithIdentifier("successView") as SuccessViewController
        self.presentViewController(successViewController, animated:true, completion:nil)

    }

    presentViewController(reader, animated: true, completion: nil)
    }
}

P.S:我正在使用QRCodeReader插件https://github.com/yannickl/QRCodeReader.swift

ios swift xcode6
1个回答
2
投票

可以关闭阅读器(QRCodeReader)后尝试显示模式视图控制器吗?文档中有QRCodeReader的回调,称为didScanResult

https://github.com/yannickl/QRCodeReader.swift

func reader(reader: QRCodeReader, didScanResult result: String) {
   self.dismissViewControllerAnimated(true, completion: { () -> Void in

       // use the result variable here.

        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        let successViewController = storyBoard.instantiateViewControllerWithIdentifier("successView") as SuccessViewController
        self.presentViewController(successViewController, animated:true, completion:nil)

   })
}

reader.completionBlock中删除代码。

© www.soinside.com 2019 - 2024. All rights reserved.