iOS
データソース メソッドから画像を取得するプロジェクトがあります。から画像を取得できるようにしたいと思いますassets library
(そして、以下のコードチャンクはこれをうまく行います)。
ただし、このdataSource
メソッドで を返す必要がありUIImage
ますが、アセット ライブラリ メソッドを使用して画像を取得すると、結果ブロックで画像が返されます。単純に結果ブロックを入れるだけreturn image
では、明らかに機能しません。
UIImage
結果ブロック内からメソッドを返す方法を知っている人はいますか? ブロック内で画像を返すことについて、他のいくつかの SO の質問を見てきましたが、それらは別のメソッドを呼び出すと言われています。残念ながら、このメソッドは UIImage を返さなければならない Nimbus データソース メソッドであるため、これを行うことはできません。
どんな助けやアドバイスも大歓迎です!以下のコード:
- (UIImage *)photoAlbumScrollView: (NIPhotoAlbumScrollView *)photoAlbumScrollView
photoAtIndex: (NSInteger)photoIndex
photoSize: (NIPhotoScrollViewPhotoSize *)photoSize
isLoading: (BOOL *)isLoading
originalPhotoDimensions: (CGSize *)originalPhotoDimensions {
__block UIImage *image = nil;
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:[_photos objectAtIndex:photoIndex]
resultBlock:^(ALAsset *asset){
ALAssetRepresentation *rep = [asset defaultRepresentation];
CGImageRef imageRef = [rep fullScreenImage];
if (imageRef) {
image = [UIImage imageWithCGImage:imageRef];
}
}
failureBlock:^(NSError *error) {
//return nil;
}];
return image;
}