0

我将一个 iPhone 应用程序转换为通用的。

我的一个功能需要从表视图控制器中的按钮从相机胶卷中选择一张照片。我收到一个错误,说我需要使用弹出控制器来执行此操作。

On iPad, UIImagePickerController must be presented via UIPopoverController'

由于这是内置代码(我从另一个开发人员那里得到这个),我可以得到一些关于在代码中正确执行此操作的建议。

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;

[self presentModalViewController:imagePicker animated:YES];

到目前为止我尝试了什么:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
////////
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext; 
////////
[self presentModalViewController:imagePicker animated:YES];

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
////////
self.modalPresentationStyle = UIModalPresentationCurrentContext;
////////
[self presentModalViewController:imagePicker animated:YES];
4

1 回答 1

0

您需要使用 UIPopoverController。

UIPopoverController *popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];

popoverController.delegate = self;

[popoverController 
     presentPopoverFromRect:sender
     permittedArrowDirections:UIPopoverArrowDirectionUp
     animated:YES];

这是一个例子: http ://www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_(Xcode_4 )

于 2012-10-01T19:23:04.517 回答