3

ユーザーがボタンを押したときにポップオーバーに表示する UIImagePickerController があります。これは iPad シミュレーターでは完全に正常に機能しますが、実際のテスト デバイスで同じことを実行しようとするとNSRangeException、イメージ ピッカーの alloc/init 行でエラーが発生します。

    imagePicker = [[UIImagePickerController alloc] init];//Crashes here on device
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) (kUTTypeImage), nil];

クラッシュメッセージは次のとおりです。

* キャッチされていない例外 'NSRangeException' が原因でアプリを終了しています。

デバッグ モードで行をステップ オーバーしようとすることで、その正確な行であると判断しました。その特定の行をステップ オーバーすると、例外がスローされます。

編集:

この問題を 100% 再現する基本的なプロジェクトを作成できたので、これは私のコードの問題ではなく、iOS のバグだと思います。

  1. 新しいプロジェクトを作成します。シングル ビュー アプリケーションを選択します。絵コンテかxibベースかは問わない
  2. iPad の xib/ストーリーボードを開き、ビューに roundrectbutton を追加します
  3. 次の IBAction をビュー コントローラーに追加します。 イヴァルpickerPopoverControllerです__strong

    -(void)iMakeItCrash:(UIButton*)sender
    {
        UIImagePickerController* ip = [[UIImagePickerController alloc] init];
        ip.delegate = self;
        ip.allowsEditing = YES;
        ip.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        ip.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) (kUTTypeImage), nil];
    
        pickerPopoverController = [[UIPopoverController alloc] initWithContentViewController:ip];
        [pickerPopoverController presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    
  4. この IBAction をボタンの Touch Up Inside イベントに接続します。

  5. シミュレーターで動作、iPad でクラッシュ

EDIT2:

を使用しようとすると、クラッシュが発生しますpresentPopoverFromBarButtonItem:。ただし、画像ピッカーをまったく表示しなくてもクラッシュしません...

4

2 に答える 2

2

いずれかのデバイスまたはシミュレーターの空の「保存済み写真」アルバムでアプリがクラッシュしたときに、これに気づきました。保存した写真に写真が含まれている場合、バグは発生しません。シミュレータで[データと設定のリセット]を使用し、アルバムを空のままにしておくと、簡単に複製できます。

回避策を見つけるために何年も費やしてきましたが、できませんでした。iOSのバグレポートを提出するのは本当に良い考えだと思います。

于 2012-05-25T21:44:49.670 に答える
0

私は一度同じ問題を抱えており、以下のコードで修正しました:

-(IBAction)actionOpenPhotoLibrary:(id)sender
{
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
    return;
}

if ([popover isPopoverVisible]) {
    [popover dismissPopoverAnimated:YES];
    return;
}

UIImagePickerController *imagePicker = [[[UIImagePickerController alloc] init]autorelease];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.delegate = self;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){

    popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];              
    popover.delegate = self;
    [popover setPopoverContentSize:CGSizeMake(320, 460)];
    [popover presentPopoverFromBarButtonItem:[[[UIBarButtonItem alloc]initWithCustomView:(UIButton*)sender] autorelease] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

imagePicker.navigationBar.tintColor = APP_THEME_COLOR;
[self presentModalViewController:imagePicker animated:YES];
}

ご多幸をお祈り申し上げます.....

于 2012-05-25T03:56:58.267 に答える