如何使用 UIPopOverController 使使用 ImagePicker 的 iPhone 应用程序在 iPhone 上运行?

发布于 2024-12-18 16:00:41 字数 709 浏览 3 评论 0原文

我正在制作一个通用应用程序,它在 iPhone 上运行得很好!但在 iPad 上,它无法调出图像选择器。代码是:

- (IBAction)openImagePicker:(id)sender //Makes UIImagePicker roll up from the bottom.
{
    UIActionSheet *alertSheet = [[UIActionSheet alloc] initWithTitle:@"Where do you want to get your daily image?" delegate:(self) cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Library", nil];
    [alertSheet setTag:0];
    [alertSheet setDelegate:self];
    [alertSheet showFromTabBar:[[self tabBarController] tabBar]];
    [alertSheet release];
}

它说原因是“*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'在iPad上,UIImagePickerController必须通过UIPopoverController呈现'”我该怎么做?感谢您的帮助。

I am making a universal app, and it works great on the iPhone! But on the iPad, it cannot pull up the image picker. The code is:

- (IBAction)openImagePicker:(id)sender //Makes UIImagePicker roll up from the bottom.
{
    UIActionSheet *alertSheet = [[UIActionSheet alloc] initWithTitle:@"Where do you want to get your daily image?" delegate:(self) cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Library", nil];
    [alertSheet setTag:0];
    [alertSheet setDelegate:self];
    [alertSheet showFromTabBar:[[self tabBarController] tabBar]];
    [alertSheet release];
}

It says the reason is "* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController'" How do I do this? Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从此见与不见 2024-12-25 16:00:41

您必须检查应用程序安装在哪种类型的设备习惯上,然后适当地显示控制器。您可以执行以下操作:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    // We are using an iPhone
    UIActionSheet *alertSheet = [[UIActionSheet alloc] initWithTitle:@"Where do you want to get your daily image?" delegate:(self) cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Library", nil];
    [alertSheet setTag:0];
    [alertSheet setDelegate:self];
    [alertSheet showFromTabBar:[[self tabBarController] tabBar]];
    [alertSheet release];
}else {
    // We are using an 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];
}

不要忘记实现 UIPopoverController 委托方法。

祝你好运

You will have to check for which type of device idiom the app is installed on and then present the controller appropriately. You can do something along the lines of the following:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    // We are using an iPhone
    UIActionSheet *alertSheet = [[UIActionSheet alloc] initWithTitle:@"Where do you want to get your daily image?" delegate:(self) cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Library", nil];
    [alertSheet setTag:0];
    [alertSheet setDelegate:self];
    [alertSheet showFromTabBar:[[self tabBarController] tabBar]];
    [alertSheet release];
}else {
    // We are using an 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];
}

don't forget to implement the UIPopoverController delegate methods.

Good Luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文