我有一个 UIImagePickerController,当用户按下按钮时,它会在弹出窗口中显示。这在 iPad 模拟器中完全正常,但是当我尝试在实际测试设备上做同样的事情时,我NSRangeException
在图像选择器的 alloc/init 行上得到一个!
imagePicker = [[UIImagePickerController alloc] init];//Crashes here on device
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) (kUTTypeImage), nil];
这是崩溃消息:
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[NSOrderedSet initWithOrderedSet:range:copyItems:]: range {8, 1} 超出范围 [0 .. 0]”
我通过尝试在调试模式下跨过该行来确定它是该行,并且跨过该特定行是引发异常的原因。
编辑:
我能够制作一个 100% 重现此问题的基本项目,这让我相信这是一个 iOS 错误,而不是我的代码。
- 做一个新项目。选择单视图应用程序。不管是故事板还是基于 xib
- 打开 iPad xib/storyboard,在视图中添加一个圆形矩形按钮
将以下 IBAction 添加到视图控制器。
pickerPopoverController
是一个__strong
伊瓦尔-(void)iMakeItCrash:(UIButton*)sender { UIImagePickerController* ip = [[UIImagePickerController alloc] init]; ip.delegate = self; ip.allowsEditing = YES; ip.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; ip.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) (kUTTypeImage), nil]; pickerPopoverController = [[UIPopoverController alloc] initWithContentViewController:ip]; [pickerPopoverController presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; }
将此 IBAction 连接到按钮的 Touch Up Inside 事件。
- 在模拟器上工作,在 iPad 上崩溃
编辑2:
如果我尝试使用presentPopoverFromBarButtonItem:
. 但是,如果我根本不提供图像选择器,也不会崩溃......