【问题标题】:ALAssetsLibrary doesn't return runloopALAssetsLibrary 不返回运行循环
【发布时间】:2013-04-04 17:08:27
【问题描述】:

我想显示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,但只有在找到所有图像后才会重新加载。

这是我的代码:

@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];

 }

【问题讨论】:

    标签: iphone objective-c uicollectionview alassetslibrary runloop


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-10
      • 2018-03-19
      • 1970-01-01
      • 2016-12-30
      • 2016-07-20
      • 1970-01-01
      • 2021-01-23
      • 2016-05-22
      相关资源
      最近更新 更多