0
私はALAssetライブラリの問題に直面しています:100個の画像ビューを持つUIViewがあります。ビューがロードされると、私はファイル名から画像を生成する関数を呼び出しています。AlAssetライブラリの問題
これが私のクラスである:
@interface myClass
{
NSString *fileName;
int pathId;
}
のviewDidLoad
-(void)viewDidLoad
{
NSMutableArray *imageCollectionArray = [self createImage:arrayOfmyClassObject];
//Here I'm binding the 100 images in UIView using the images in imageCollectionArray
}
これは、私が問題に見つけている私の方法であって、ときに私の負荷
- (NSMutableArray *)createImage:(NSMutableArray *)imageFileNamesArray
{
imageArray = [[NSMutableArray alloc] init];
for (int imageNameKey = 0; imageNameKey<100; imageNameKey++)
{
myClass *obj= [imageFileNamesArray objectAtIndex:imageNameKey];
if(obj.pathId == 0)
{
//Here adding the bundle image into the imageArray
[imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:obj.fileName ofType:@"png" inDirectory:@"Images"]]];
}
else
{
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset); typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) {
};
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *images;
if (iref)
{
//Here adding the photo library image into the imageArray
images = [UIImage imageWithCGImage:iref];
[imageArray addObject:images];
}
else
{
//Here adding the Nofile.png image into the imageArray if didn't find a photo library image
images = [UIImage imageNamed:@"Nofile.png"];
[imageArray addObject:images];
}
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror) {
//Here adding the Nofile.png image into the imageArray if any failure occurs
[imageArray addObject:[UIImage imageNamed:@"Nofile.png"]];
NSLog(@"booya, cant get image - %@",[myerror localizedDescription]);
};
NSURL *asseturl = [NSURL URLWithString:obj.fileName];
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:asseturl
resultBlock:resultblock failureBlock:failureblock];
}
}
return imageArray;
}
問題でした最初にアセットライブラリの画像が生成されていないビュー、私は別のビューのいずれかに行くと100の画像ビューに戻って資産画像が生成された場合は、バンドル画像だけが表示されました。問題は、同じ機能が最初の負荷でアセット画像を生成しないということです。どうすればこの問題を解決できますか?前もって感謝します。
私は、このコードをコンパイルできるとは思わない。 – jamapag
あなたのコードを理解できません。どこでもかっこ。 – memmons
奇妙なコード... ALAssetが非同期であることを忘れないでください。すべての画像がロードされたときにsetNeedsDisplayを実行する必要があります。 – Johnmph