0

我在从 iPhone(iOS 8.4)的图像库中选择图像时遇到问题。

这是我的代码:

   UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
   imagePicker.delegate = self;
   imagePicker.allowsEditing = NO;
   imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
   [self presentModalViewController:imagePicker animated:YES];

但是,如果我同时选择一个图像并交换该图像,它会打开一个编辑视图,然后如果我尝试删除该图像,我的应用程序就会崩溃。

它是图像库的默认功能吗?还是可以通过代码处理?

请告诉我。提前致谢

4

1 回答 1

0

如果你能试试

NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
    void (^assetGroupEnumerator) (ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
    {
        if(group != nil)
        {
            [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
             {
                 //ALAssetRepresentation holds all the information about the asset being accessed.
                 if(result)
                 {
                     ALAssetRepresentation *representation = [result defaultRepresentation];

                     if (representation !=nil)
                     {
                         UIImage *PhotoThumbnail = [UIImage imageWithCGImage:[result thumbnail]];
                         [fetchedThumbnails addObject:PhotoThumbnail];
                         UIImage * latestPhoto = [UIImage imageWithCGImage:[result thumbnail]];
                         [fetchedImages addObject:latestPhoto];
                     }
                 }
             }];
            [assetGroups addObject:group];
        }

        galleryImagesCV.hidden=NO;
        [galleryImagesCV reloadData];
    };

    assetGroups = [[NSMutableArray alloc] init];
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    NSUInteger groupTypes = ALAssetsGroupSavedPhotos;

    [library enumerateGroupsWithTypes:groupTypes usingBlock:assetGroupEnumerator failureBlock:^(NSError *error)
     {
        NSLog(@"A problem occurred");
     }];

导入 AssetsLibrary/AssetsLibrary.h

这将为您提供数组中图库中的所有图像。您可以在自定义视图中显示这些并选择/交换等。

希望能帮助到你

于 2016-06-23T05:11:00.633 回答