2

自从升级到 XCode 5/iOS 7 后,在调用应该呈现 Redlaser SDK 条形码选择器控制器的函数时出现以下错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图在目标上呈现一个 nil 模态视图控制器。” *首先抛出调用栈:

(

0   CoreFoundation                      0x02ef25e4 __exceptionPreprocess + 180

1   libobjc.A.dylib                     0x028dd8b6 objc_exception_throw + 44

2   UIKit                               0x006e817a -[UIViewControllerpresentViewController:withTransition:completion:] + 4879

3   UIKit                               0x006e8caf -[UIViewController presentViewController:animated:completion:] + 130
4   UIKit                               0x006e8cef -[UIViewController presentModalViewController:animated:] + 56
5   Extinguishers                       0x0000b703 -[LoginViewController scanPressed] + 1299

这是我的方法导致它:

-(IBAction) scanPressed
{   
if (overlayController.parentPicker == nil)
{
    BarcodePickerController * picker = [[BarcodePickerController alloc] init];

    [picker setOverlay:overlayController]; 
    [picker setDelegate:self];

    // Initialize with portrait mode as default
    picker.orientation = UIImageOrientationUp;

    // The active scanning region size is set in OverlayController.m
}

// Update barcode on/off settings
[overlayController.parentPicker setScanUPCE:YES];
[overlayController.parentPicker setScanEAN8:YES];
[overlayController.parentPicker setScanEAN13:YES];
//[overlayController.parentPicker setScanSTICKY:YES];
//[overlayController.parentPicker setScanQRCODE:YES];
[overlayController.parentPicker setScanCODE128:YES];
[overlayController.parentPicker setScanCODE39:YES];
[overlayController.parentPicker setScanITF:YES];

// Data matrix decoding does not work very well so it is disabled for now
[overlayController.parentPicker setScanDATAMATRIX:NO];

// hide the status bar
[[UIApplication sharedApplication] setStatusBarHidden:YES];

// Show the scanner overlay - THIS LINE CAUSES THE CRASH
    [self presentModalViewController:overlayController.parentPicker animated:TRUE];

}

我也试过升级到最新版的Redlaser SDK,还是一样。在切换到 iOS 7 作为基础 SDK 之前,我没有遇到这个问题。

4

1 回答 1

0

我唯一能想到的是picker(父级)可能超出范围并被释放。在错误行之前进行测试以检查父级是否仍然存在:if(overlayController.parentPicker == nil) NSLog(@"Parent is nil");

如果确实如此nil(就像您最初的错误所说的那样),请尝试在第一条语句picker 之前if声明。

BarcodePickerController *picker;
if(overlayController.parentPicker == nil)
{
    picker = [[BarcodePickerController alloc] init];
//...

子级可能只有一个weak指向父级的指针,因此您可能需要将父级声明为 a或在将其从堆栈中弹出@property之前不会被释放的地方。viewController

于 2013-10-04T14:53:11.517 回答