나는 UICollectionView
을 표시하고 싶지만 이미지를로드하는 데 문제가 있습니다. AlAssetsLibrary
은 runloop으로 돌아 가지 않습니다.ALAssetsLibrary는 runloop을 반환하지 않습니다
제가
2013-04-12 11:36:25.429 Filmriss[459:907] didReturnWithDefaultRepresentation
2013-04-12 11:36:25.438 Filmriss[459:907] cellForItemAtIndexPath
2013-04-12 11:36:25.450 Filmriss[459:907] cellForItemAtIndexPath
2013-04-12 11:36:25.456 Filmriss[459:907] cellForItemAtIndexPath
didReturnWithDefaultRepresentation
방법마다 잔상이라고 2013-04-12 11:36:25.431 Filmriss[459:907] didReturnWithDefaultRepresentation
2013-04-12 11:36:25.435 Filmriss[459:907] didReturnWithDefaultRepresentation
로 출력을 얻는다. 이 방법에서는 Collection-view를 다시로드하지만 모든 이미지를 찾은 후에 만 다시로드합니다. Heres는
내 코드 :
@implementation PhotoEngine
-(void)startLookingForPhotosBetween:(NSDate*)startDate andEndDate:(NSDate*)endDate
{
BOOL __block isValid = NO;
NSMutableArray *representationArray = [NSMutableArray new];
ALAssetsLibrary *assetLibrary = [ALAssetsLibrary new];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:
^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (!asset && (index == NSNotFound))
{
if ([self.delegate respondsToSelector:@selector(photoEngine:didFinishWithResults:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate photoEngine:self didFinishWithResults:representationArray];
});
}
}
else {
ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation];
NSDate *creationDate = [asset valueForProperty:ALAssetPropertyDate];
if (
([startDate compare:creationDate] == NSOrderedAscending) &&
([endDate compare:creationDate] == NSOrderedDescending)
) {
isValid = YES;
}
if(isValid) {
[representationArray addObject:defaultRepresentation.url];
NSURL *url = defaultRepresentation.url;
if ([self.delegate respondsToSelector:@selector(photoEngine:didReturnWithDefaultRepresentation:)]) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[self.delegate photoEngine:self didReturnWithDefaultRepresentation:url];
});
}
}
}
}];
}
// group == nil signals we are done iterating.
else {
dispatch_async(dispatch_get_main_queue(), ^{
});
}
}
failureBlock:^(NSError *error) {
NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];
}
@end
// didReturnWithDefaultRepresentation this Method is in CollectionView
-(void)photoEngine:(PhotoEngine*)photoEngine didReturnWithDefaultRepresentation:(NSURL *)defaultRepresentationURL
{
NSLog(@"didReturnWithDefaultRepresentation");
[self.photoDataArray addObject:defaultRepresentationURL];
[self.collectionView reloadData];
}