0

Possible Duplicate:
UIPopover for iphone 4.0

I have a universal app in Xcode. If the user is using an iPad the use image from library button works great. However if they use an iPhone the button doesn't work.

Here is the error I receive.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.'

Help please!

Here is my code.

- (IBAction) useCameraRoll: (id)sender
{

if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];

} else {
if ([UIImagePickerController isSourceTypeAvailable:
     UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
    UIImagePickerController *imagePicker =
    [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType =
    UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              nil];
    imagePicker.allowsEditing = YES;

    newMedia = NO;
}
}
}

How would I incorporate the following code? if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { Add Popover code here } else {
Add alternative for popover here }

Community
  • 1
  • 1

1 Answers1

0

The reason for crash is UIPopoverController is available only for iPad, you cannot use it while running on IPhone. So you need look alternative for it.

Sahil Arora
  • 213
  • 3
  • 8
  • Try this answer if you want to make something very similar to UiPopoverController in IPhone http://stackoverflow.com/a/4124016/1451709 – Sahil Arora Sep 06 '12 at 14:12
  • Is there a way to keep it for the iPad and remove it for the iPhone? – Niche' Ad Marketing Sep 06 '12 at 14:18
  • Yes, you can achieve it. Just simply check whether the application is running on Iphone or Ipad. Use following code if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { Add Popover code here } else { Add alternative for popover here } – Sahil Arora Sep 06 '12 at 14:26
  • Ok Sahil I added my code to this question. Please advise to how I would use your code. Thank you – Niche' Ad Marketing Sep 06 '12 at 16:01
  • You need to add this code to place where you have added the popover into the application. It should look something like - self.popoverController = [[UIPopoverController alloc] initWithContentViewController:View]; [popover presentPopoverFromRect:CGRectMake(button.frame.size.width / 2, button.frame.size.height / 1, 1, 1) inView:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; – Sahil Arora Sep 06 '12 at 17:07
  • ok so how would it look in the code shown above? – Niche' Ad Marketing Sep 06 '12 at 18:59