这里根据需要,我的相册页面是仿照系统相册进行的自定义,
这里我的问题是,
第一次调用相册页面选取图像,获得图像,没有问题,之后再跳到照相机页面,拍摄图片,此时也进行获得头像,也是可以的,
但是这样调用完之后,我想要再次调用之前自定义的相册页面,选取图像,进行图像的获得时,程序崩溃,
崩溃信息:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage valueForProperty:]: unrecognized selector sent to instance 0x147b2210'
感觉是报野指针的错误,但是这里的一系列操作,我都没有进行内存的释放,因为我的项目里面用的是ARC,所以在这里我不知道为什么会报这个错误,
我的代码如下,
// 从相册获取图片
- (void) localPhoto {
if ([UtilityFunc isPhotoLibraryAvailable])
{
TAMultiImagePickerController *picker = [[TAMultiImagePickerController alloc] init];
picker.delegate = self;
if (_imagePickerArray != nil) {
picker.selectedAssets = _imagePickerArray;
}
[self presentViewController:picker animated:YES completion:nil];
}
}
+ (BOOL) isPhotoLibraryAvailable{
return [UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary];
}
// 完成自定义相册里的图片选取的回调
- (void)multiImagePickerController:(TAMultiImagePickerController *)picker didFinishPickingImages:(NSArray *)imagesArray
{
if (self.popover != nil)
[self.popover dismissPopoverAnimated:YES];
else
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
// NSArray *tempArray = [NSMutableArray arrayWithArray:imagesArray];
NSMutableArray *tempArray = [NSMutableArray array];
for (ALAsset *alsset in imagesArray) {
UIImage *image = [self fullResolutionImageFromALAsset:alsset];
[tempArray addObject:image];
}
_imagePickerArray = tempArray;
[self createImagePickerScrollView];
NSMutableArray *array = [NSMutableArray array];
for (UIImage *image in _imagePickerArray) {
NSData* data = UIImageJPEGRepresentation(image, 1.0);
[array addObject:data];
}
[_dataDict setObject:array forKey:@"imageArray"];
// _departure.imageArray = array;
}
// 拍照
- (void) takePhoto {
if ([UtilityFunc isCameraAvailable] && [UtilityFunc doesCameraSupportTakingPhotos]) {
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UtilityFunc isFrontCameraAvailable]) {
controller.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
controller.navigationBar.backgroundColor = [UIColor navBarColor];
NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
[mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
controller.mediaTypes = mediaTypes;
controller.delegate = self;
[self presentViewController:controller
animated:YES
completion:^(void){
}];
}
}
// 完成拍照后的回调
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *portraitImg = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
portraitImg = [portraitImg imageByScalingToMaxSize];
ImageCropperViewController *imgEditorVC = [[ImageCropperViewController alloc] initWithImage:portraitImg cropFrame:CGRectMake(0, 100.0f, self.view.frame.size.width, self.view.frame.size.width) limitScaleRatio:3.0];
imgEditorVC.delegate = self;
[picker pushViewController:imgEditorVC animated:YES];
}
#pragma mark VPImageCropperDelegate
- (void)imageCropper:(ImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage {
[_imagePickerArray addObject:editedImage];
[self createImagePickerScrollView];
[cropperViewController.navigationController dismissViewControllerAnimated:YES completion:nil];
}