ios - iPad上的UIIMagePicker查看照片库崩溃

标签 ios

我正在尝试让我的 imagePicker 从我的 sourceLibrary 加载照片。使用以下代码,应用程序崩溃并显示以下消息“应用程序试图以模态方式呈现事件 Controller ”

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


}

最佳答案

注释代码

[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];

      }

关于ios - iPad上的UIIMagePicker查看照片库崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17042116/

相关文章:

ios - 来自 UITableViewCell 中的按钮的 UIPopoverPresentationController

ios - 推送 View : while an existing transition or presentation is occurring; the navigation stack will not be updated

ios - 如何在 iOS 中取消 UIScrollView 滚动到三角形 UIView 之外?

ios - 将 url 字符串与 NSString stringWithFormat 一起使用的最佳做法是什么

ios - 如何处理 Swift 3 中 UNUserNotificationCenter 和 FIRMessaging w/Firebase 的委托(delegate)?

ios - 建立网络连接后,我可以让 iOS 7 在后台发送图片吗?

ios - AVAssetWriterInput appendSampleBuffer 成功,但从 CMSampleBufferGetSampleSize 记录错误 kCMSampleBufferError_BufferHasNoSampleSizes

ios - 与蜂窝网络相比,React-native 在 wifi 上的获取速度极慢。在开发和生产中,无论运行/不调试器

iOS:如何为原生 iPhone 图片添加 Alpha channel

ios - 我可以与应用组共享 iOS Realm 数据库吗?