ios - MonoTouch,ZXing : Presenting ZXingScannerViewController failed

标签 ios uinavigationcontroller xamarin.ios xamarin zxing

所以在我的应用程序开始时,用户必须能够扫描二维码。在应用程序设置中,用户可以扫描另一个条形码以更改设置中的一些数据。

在我的应用程序扫描仪开始时工作正常,但是当我尝试在 settingVC 中扫描条形码时,我收到以下警告:

Warning: Attempt to present ZXing.Mobile.ZXingScannerViewController: 0x18036dc0 on UINavigationController: 0x16d8afe0 whose view is not in the window hierarchy!

我已经尝试在 viewDidAppear 上调用扫描,但我收到了相同的警告。

            button_ScanAPI.TouchUpInside += async (sender, e) => {
                var scanner = new ZXing.Mobile.MobileBarcodeScanner ();
                var result = await scanner.Scan ();

                if (result != null) {
                    textField_APIKey.Text = result.Text;
                }   
            };

编辑:

尝试在没有异步的情况下使用条形码扫描仪,但我仍然收到相同的消息。

var scanner = new ZXing.Mobile.MobileBarcodeScanner ();
                scanner.Scan (true).ContinueWith (t => {   
                    if (t.Result != null) {

                        InvokeOnMainThread (() => {
                            textField_APIKey.Text = t.Result.Text;

                        });
                    }
                });

我也尝试使用 AVFoundation 导致同样的错误:

Warning: Attempt to present <AVCaptureScannerViewController: 0x16fb1d00> on <UINavigationController: 0x16ebe790> whose view is not in the window hierarchy!

编辑 2:

这是我的应用中流程的一部分。

enter image description here

最佳答案

我认为默认情况下 ZXing 库必须寻找最顶层的 NavigationController 并尝试从那里呈现模态视图 Controller 。像您一样,我在根 NavigationController 的顶部以模态方式呈现了另一个 NavigationController。我能够通过将构造函数更改为以下内容来解决此问题:

var scanner = new MobileBarcodeScanner (this);
var result = await scanner.Scan ();

“this”是您实际从中调用扫描仪的 ViewController。

关于ios - MonoTouch,ZXing : Presenting ZXingScannerViewController failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20731716/

相关文章:

ios - UINavigationController 在推送时显示状态栏的空间

xamarin.ios - 为什么我必须保留对 UIViewController 的引用以防止它被垃圾收集?

c# - monotouch.dialog styledstringelement调整单元格宽度

ios - Xamarin iOS 应用程序。辞去分配资料。错误 : "Invalid Signature. A sealed resource is missing or invalid"

iphone - 三元运算在iPhone中是否比 "if/else"更好

ios - iOS 7 和 8 的 UITableViewCells 自动布局指标不同

iOS 开发——检查所有 UI 对象是否具有可访问性标签/标识符?

ios - 当 NavigationController 更改 View 时,UIToolBar 更改为黑色

ios - 导航栏上的按钮不拾取窗口色调颜色

ios - Qt Apple 推送通知