0

iPhone と iPad の両方に対応するユニバーサル アプリがあります。以下のコードを使用して、写真ライブラリまたはカメラから画像を取得しようとしています。iPhoneの場合は正常に動作しますが、iPadの場合、アラートビューからボタンをクリックしても何も表示されません。何が問題になる可能性がありますか?

-(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];
}
4

2 に答える 2

1

これは、iPad で UIActionSheet を使用しているためです。iPad では、UIActionSheet は UIPopoverController を使用してシートを表示し、UIActionSheetDelegate メソッドでは、UIActionsheet によって使用される最初の UIPopoverController が非表示になっていない場合、別の UIPopoverController を使用します。知っておく必要があるのは、画面に表示される UIPopoverController は常に 1 つだけであるということだけです。

于 2013-07-17T01:34:38.563 に答える
0

それはこの行です:

[popoverController presentPopoverFromRect:[self.view bounds] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

コントローラーのビュー内にある四角形から表示する必要があります (selfビューコントローラーであると想定しています)。そうしないと、奇妙な結果が得られます。たった今のテストでは、ポップオーバーが 1 つ表示されず、矢印の先端が画面の中央に表示されたものもありました。たとえば、次のようになります。

[popoverController presentPopoverFromRect:[myButtonOutlet frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
于 2012-08-25T23:51:46.200 に答える