iphone - UIPopoverController 不显示在 iPad 上

标签 iphone ios ipad

我有一个适用于 iPhone 和 iPad 的通用应用程序。使用下面的代码我尝试从照片库或相机获取图片。对于 iPhone,它工作正常,但对于 iPad,当我单击警报 View 中的任何按钮时,它不会显示任何内容。可能是什么问题?

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

    if (buttonIndex == 0) {
        UIImagePickerController* picker = [[UIImagePickerController alloc] init];
        picker.allowsEditing = YES;
        picker.delegate   = self;
        camera = NO;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentModalViewController:picker animated:YES];


    } else if (buttonIndex == 1) {

        BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
        camera = YES;
        UIImagePickerController* picker = [[UIImagePickerController alloc] init];
        picker.allowsEditing = YES;
        picker.delegate   = self;
        picker.sourceType = hasCamera ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentModalViewController:picker animated:YES];

        }
    }else {
    // We are using an iPad
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
    popoverController.delegate=self;
    [popoverController presentPopoverFromRect:[self.view bounds] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if (clickedButton == YES) {

            UIImage *originalImage, *editedImage;

            editedImage = (UIImage *) [info objectForKey: UIImagePickerControllerEditedImage];

            originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage];

            if (editedImage) {

                thisImage = editedImage;

            } else {

                thisImage = originalImage;

            }

            imageThis.image = thisImage;

        NSData *imageData = UIImageJPEGRepresentation(thisImage, 30);

        [defaults setObject:imageData forKey:@"thisImage"];

        [defaults synchronize];

     //   [[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(thisImage) forKey:@"thisImage"];

    }
    else {

        UIImage *originalImage, *editedImage;

        editedImage = (UIImage *) [info objectForKey: UIImagePickerControllerEditedImage];

        originalImage = (UIImage *) [info objectForKey: UIImagePickerControllerOriginalImage];

        if (editedImage) {

            thatImage = editedImage;

        } else {

            thatImage = originalImage;

        }

        imageThat.image = thatImage;

        NSData *imageData = UIImageJPEGRepresentation(thatImage, 30);

        [defaults setObject:imageData forKey:@"thatImage"];

        [defaults synchronize];

        //[[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(thatImage) forKey:@"thatImage"];

    }

    [picker dismissModalViewControllerAnimated:YES];
}

最佳答案

那是因为您在 iPad 上使用 UIActionSheet。在 iPad 上,UIActionSheet 使用 UIPopoverController 来呈现工作表,并且在 UIActionSheetDelegate 方法中,当 UIActionsheet 使用的第一个 UIPopoverController 尚未隐藏时,您可以使用另一个 UIPopoverController。您需要知道的是,任何时候屏幕上只能显示一个 UIPopoverController。

关于iphone - UIPopoverController 不显示在 iPad 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12126126/

相关文章:

ipad - 内存超过40MB时,基于Unity的应用程序在iPad 1上崩溃

iphone - 如何使具有不同 subview 的UITableViewCell可重用?

iphone - 如何在iPhone应用程序中隐藏UISearchBar

ios - 如何使用 Storyboards 和 Tab Bar Controller 作为初始 Controller 共享 UIManagedDocument?

ios - 应该对表格单元格内具有可变高度的图像应用什么约束(Swift)?

ios - 如何在 UIImageView 中创建从左到右淡入淡出的动画(alpha 渐变)

iPhone 开发 - 在哪里可以获得应用程序接收到的所有信号及其含义的列表

iphone - iOS 应用内购买 skproductrequest 随机没有返回任何产品

ios - 当应用程序处于后台时播放音频或声音

iphone - 有没有办法从字面上暂停 View ?