2013-10-25 2 views
0

그래, ImagePicker를 모두 설치하고 ALAssetLibrary를 설정하여 그림과 제목 (기존 그림이나 새 그림의 일반 텍스트가있는 경우)을 얻을 수 있지만 지금은 가능한 방법이 있는지 알아 내려고 노력하고 있습니다. assetForURL 메소드의 블록 호출 외부에서이 정보에 액세스하십시오. 그래서 여기에 단지 내가 (resultBlock 외부에서 ALAssets 정보에 액세스하는 방법이 있습니까?

__block NSString *documentName; 
    __block UIImage *docImage; 
    NSURL *resourceURL = [imageInfo objectForKey:UIImagePickerControllerReferenceURL]; 
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset) 
    { 
     ALAssetRepresentation *imageRep = [asset defaultRepresentation]; 
     //Get Image 
     CGImageRef iref = [imageRep fullResolutionImage]; 
     //If image is null then it's a new picture from Camera 
     if (iref == NULL) { 
      docImage = [imageInfo objectForKey:UIImagePickerControllerOriginalImage]; 
      documentName = @"New Picture"; 
     } 
     else { 
      docImage = [UIImage imageWithCGImage:iref]; 
      documentName = [imageRep filename]; 
     } 
    }; 
    // get the asset library and fetch the asset based on the ref url (pass in block above) 
    ALAssetsLibrary *imageAsset = [[ALAssetsLibrary alloc] init]; 
    [imageAsset assetForURL:resourceURL resultBlock:resultblock failureBlock:nil]; 

가 지금은 두 개의 변수를 사용할 수 있도록하려면 (이 사진의 선택이 이루어진 후 표시되는 화면의 viewDidLoad 방법에) 무슨 일이 일어나고 있는지 보여줄 수있는 내 코드는 documentName 및 docImage)이 ViewController의 다른 곳 (예를 들어 문서 이름을 저장하기 전에 문서의 이름을 변경하려는 경우 기본 이름으로 되돌릴 수 있기를 원하지만 필요한 항목을 찾을 수없는 경우) 이 변수는 나중에 사용할 수 있습니다. 이것이 합리적인지 아닌지는 모르겠으므로 다른 것을 명확히해야 할 필요가 있으면 알려주십시오.

답변

0

좋아요. 문제는 코드가 아니라 어떻게 사용했는지에 대한 내 논리로 알았습니다. ImagePicker 화면에서이 작업을 수행 한 다음 결과 블록 코드에서 Modal 창을 호출하는 대신 이미지를 선택한 후에 표시되는 모달 뷰에서이 작업을 수행하려고했습니다.

관련 문제