UIImagePickerController crashes on alloc / init

I have a UIImagePickerController which I show in a popover when the user clicks a button. This works fine in the iPad simulator, but when I try to do the same on a real test device, I get NSRangeExceptionin the alloc / init line for my selection of images!

    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];

Here is the error message:

* Application termination due to an uncaught exception 'NSRangeException', reason: '* - [NSOrderedSet initWithOrderedSet: range: copyItems:]: range {8, 1} goes beyond [0 .. 0]'

I determined that it was the exact line trying to step over the line in debug mode and step over this particular line - this is what causes the exception.

EDIT:

, 100%, , iOS, - .

  • . . , xib-based
  • iPad xib/,
  • IBAction viewcontroller. pickerPopoverController __strong ivar

    -(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

EDIT2:

, presentPopoverFromBarButtonItem:. , , ...

+3
2

, " " . , . , Reset .

, , . , iOS - .

+2

:

-(IBAction)actionOpenPhotoLibrary:(id)sender
{
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
    return;
}

if ([popover isPopoverVisible]) {
    [popover dismissPopoverAnimated:YES];
    return;
}

UIImagePickerController *imagePicker = [[[UIImagePickerController alloc] init]autorelease];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.delegate = self;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){

    popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];              
    popover.delegate = self;
    [popover setPopoverContentSize:CGSizeMake(320, 460)];
    [popover presentPopoverFromBarButtonItem:[[[UIBarButtonItem alloc]initWithCustomView:(UIButton*)sender] autorelease] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

imagePicker.navigationBar.tintColor = APP_THEME_COLOR;
[self presentModalViewController:imagePicker animated:YES];
}

.....

0

All Articles