0

我正在尝试将图像加载到为 iphone 制作的应用程序中的图像视图,但也应该支持在 ipad 上运行。因此,当我在 iphone 模拟器中加载图像时,它可以正常工作,但是当我切换到 ipad 模拟器时,图像不会加载到 imageview 中。有什么建议么??

- (IBAction)chooseImage:(id)sender
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {


//iPhone
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:self.imagePicker animated:YES completion:nil];

}
else {
//iPad

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate=self;
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];}


}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.image = info[UIImagePickerControllerOriginalImage];
[self.imageView setImage:self.image];
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];

}
4

4 回答 4

0

你没有在你的 Ipad 编码中设置 sourceType 在你的 iPad 编码中添加这一行

[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

并且还在 delgate 方法中将 Popover 视为评论中提到的

于 2013-04-12T06:57:46.977 回答
0

对于 iPad,

[popoverController presentPopoverFromRect:[sender frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
于 2013-04-12T06:54:51.693 回答
0
- (IBAction)chooseImage:(id)sender
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {


//iPhone
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:self.imagePicker animated:YES completion:nil];

}
else {
//iPad

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate=self;
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];}

}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

if
    ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.image = info[UIImagePickerControllerOriginalImage];
[self.imageView setImage:self.image];
[self dismissViewControllerAnimated:YES completion:nil];

}
else {
    [self dismissViewControllerAnimated:YES completion:NULL];

}
}
于 2013-04-12T07:23:21.643 回答
0

使用 UIPopoverController 在 iPad 中呈现 UIImagePicker。

于 2013-04-12T08:41:14.267 回答