0

imagePicker に sourceLibrary から写真をロードさせようとしています。次のコードを使用すると、「アプリケーションがアクティブなコントローラーをモーダルに提示しようとしました」というメッセージでアプリがクラッシュします。

-(void)viewPhotoLibrary{
NSLog(@"get photos");



UIImagePickerController  *imagePickerController =
[[UIImagePickerController alloc] init];


    UIPopoverController  *pop = [[UIPopoverController alloc]
                                   initWithContentViewController:imagePickerController];
    pop.delegate = self;
    [pop setPopoverContentSize:CGSizeMake(500, 500)];



    [pop presentPopoverFromRect:
     CGRectMake(0, 0, 500, 500)
                           inView:self.view
         permittedArrowDirections:UIPopoverArrowDirectionAny
                        animated:YES];






    [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    [imagePickerController setDelegate:self];
    [imagePickerController setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:imagePickerController animated:YES completion:nil];


}
4

1 に答える 1

2

コードにコメントする

[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:(id)self];
[imagePickerController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:imagePickerController animated:YES completion:^{

}];

またはこのコードを使用してください

-(void)viewPhotoLibrary{
NSLog(@"get photos");

 UIImagePickerController  *imagePickerController =
[[UIImagePickerController alloc] init];


  UIPopoverController  *pop = [[UIPopoverController alloc]
                               initWithContentViewController:imagePickerController];
  pop.delegate = self;
  [pop setPopoverContentSize:CGSizeMake(500, 500)];



  [pop presentPopoverFromRect:
   CGRectMake(0, 0, 500, 500)
                       inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionAny
                    animated:YES];

      }
于 2013-06-11T10:47:26.673 に答える