14

イメージ ピッカーからイメージを選択した後、モーダル ビュー コントローラーを作成しようとしています。私はコードを使用します:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

   NSLog(@"Picker has returned");
   [self dismissModalViewControllerAnimated:YES];



   // TODO: make this all threaded?
   // crop the image to the bounds provided
   img = [info objectForKey:UIImagePickerControllerOriginalImage];
   NSLog(@"orig image size: %@", [[NSValue valueWithCGSize:img.size] description]);

   // save the image, only if it's a newly taken image:
   if([picker sourceType] == UIImagePickerControllerSourceTypeCamera){
      UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
   }

   // self.image_View.image=img;
   //self.image_View.contentMode = UIViewContentModeScaleAspectFit;


   ModalViewController *sampleView = [[ModalViewController alloc] init];
   [self presentModalViewController:sampleView animated:YES];
}

ただし、次の警告が表示されます。

Warning: Attempt to present <ModalViewController: 0x7561600> on <ViewController: 0x75a72e0> while a presentation is in progress!

モーダル ビューは表示されません。

私は何を間違っていますか?

4

2 に答える 2

28
- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info {

     // TODO: make this all threaded?
     // crop the image to the bounds provided
     img = [info objectForKey:UIImagePickerControllerOriginalImage];
     NSLog(@"orig image size: %@", [[NSValue valueWithCGSize:img.size] description]);

     // save the image, only if it's a newly taken image:
     if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
         UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
     }

     // self.image_View.image = img;
     // self.image_View.contentMode = UIViewContentModeScaleAspectFit;

    NSLog(@"Picker has returned");
    [self dismissViewControllerAnimated:YES
                             completion:^{
                                ModalViewController *sampleView = [[ModalViewController alloc] init];
                                [self presentModalViewController:sampleView animated:YES];
                             }];
}
于 2012-11-30T09:34:49.727 に答える
5

ここで問題が発生しているのは、最初にを却下しUIImagePicker、すぐに別のビューをモーダルビューとして表示しているためです。そのため、このエラーが発生します。

次のコードで確認してください。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

 [self dismissViewControllerAnimated:NO completion:^{

     img = [info objectForKey:UIImagePickerControllerOriginalImage];
     NSLog(@"orig image size: %@", [[NSValue valueWithCGSize:img.size] description]);

     if([picker sourceType] == UIImagePickerControllerSourceTypeCamera)
     {
         UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
     }

     ModalViewController *sampleView = [[ModalViewController alloc] init];
    [self presentModalViewController:sampleView animated:YES];
  }];
}
于 2012-11-30T09:32:20.800 に答える