我正在使用UIImagePicker从库中加载图像,但它提供了异常 说使用popover for ipad.I尝试了那些但是没有任何想法如何解决这个问题。
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
答案 0 :(得分:2)
在ipad或iphone中打开UIImagePicker使用Bellow代码: -
#define isiPhone(UI_USER_INTERFACE_IDIOM()== 0)?TRUE:FALSE
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if (isiPhone) {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
{
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pckrImage animated:YES];
}
else {
}
}
else
{
popover = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
[popover presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
解雇时选择UIImaegPicker: -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if(isiPhone)
{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
else
{
[popover dismissPopoverAnimated:YES];
}
}
答案 1 :(得分:0)
在iPad中,您必须使用它:
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController: picker];
[popover presentPopoverFromBarButtonItem: item
permittedArrowDirections: UIPopoverArrowDirectionAny
animated: YES];
或
[popover presentPopoverFromRect: CGRectMake(0, 0, 100, 100)
inView: self.view
permittedArrowDirections: UIPopoverArrowDirectionAny
animated: YES];