2016-06-23 6 views
2

iPhone(iOS 8.4)の画像ライブラリから画像を選択する際に問題があります。ここで 編集ビューにならないように、画像ライブラリから同時に画像を選択して入れ替えるのを防ぐには?

は私のコードです:

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

しかし、私は、画像を選択すると同時に、その画像を交換する場合、私はそのイメージを削除しようとする場合には、その後、私のアプリのクラッシュを編集ビューを開きます。

イメージライブラリのデフォルト機能ですか?それとも、コードで扱うことができますか?

お知らせください。事前

答えて

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

を試みることができる場合。あなたは

などカスタムビューでこれらを表示し、/スワップを選択することができますので、ありがとうございましたが、私は別のビューを使用して、それをカスタマイズしたくない、それは

+0

をお役に立てば幸いです。 特定の画像を削除しようとするとこのエラーが発生します。 コンテキストを保存できませんでした:エラードメイン= NSCocoaErrorDomainコード= 134030 "操作を完了できませんでした(Cocoa error 134030.)" null)(null) –

+0

Obj-Cコードでライブラリから画像を削除しますか? – gurmandeep

+0

ええ、私はその昨夜のバグを見つけました。 ライブラリから画像を選択するためのUIImagePickerControllerを開きます。その画像を選択して同時にその画像を突然スワップすると、画像は編集ビューで開きます(iOSではその機能が組み込まれています)。その画面からその画像を削除すると、アプリがクラッシュするためです。 私はこのリンクを通過しました - http://stackoverflow.com/questions/20270714/why-would-app-try-to-save-to-plsharedmanagedobjectcontext しかし、私の場合は何も起こりません。 –

関連する問題