首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ALAssetsLibrary不返回runloop

ALAssetsLibrary不返回runloop
EN

Stack Overflow用户
提问于 2013-04-12 16:44:44
回答 1查看 270关注 0票数 3

我想显示一个UICollectionView,但我在加载图像时遇到了问题。AlAssetsLibrary不会返回到运行循环。

我得到的输出是

2013-04-12 11:36:25.429 Filmriss[459:907] didReturnWithDefaultRepresentation 2013-04-12 11:36:25.431 Filmriss[459:907] didReturnWithDefaultRepresentation 2013-04-12 11:36:25.435 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方法。在此方法中,我尝试重新加载Collection-view,但它仅在找到所有图像后才重新加载。

下面是我的代码:

代码语言:javascript
复制
@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];

 }
EN

回答 1

Stack Overflow用户

发布于 2014-05-12 17:27:34

首先,必须在主标题中修复self.collectionView reloadData;。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15966843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档