自从升级到XCode 5 / iOS 7后,我在调用一个应该呈现Redlaser SDK barcodepickercontroller的函数时遇到以下错误:
由于未捕获的异常'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之前,我没有遇到此问题。
答案 0 :(得分:0)
我唯一能想到的是picker
(父母)可能超出范围并被取消分配。在错误线之前进行测试以检查父级是否仍然存在:if(overlayController.parentPicker == nil) NSLog(@"Parent is nil");
如果确实是nil
(就像您原来的错误所说的那样),请尝试在之前声明picker
第一个if
声明。
BarcodePickerController *picker;
if(overlayController.parentPicker == nil)
{
picker = [[BarcodePickerController alloc] init];
//...
孩子可能只有weak
指向父母的指针,因此您可能需要将父级声明为@property
或在viewController
之前不会取消分配的地方从堆栈中弹出。