我试图让我的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];
}
答案 0 :(得分: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];
}