加载照片时更新PSTCollectionView内容

时间:2013-03-28 07:55:58

标签: objective-c uicollectionview alassetslibrary pstcollectionview

我正在使用PSTCollectionView class从iPhone相机胶卷加载照片。我希望照片在加载时显示,而不是等到所有内容都被读取。我的代码如下所示:

-(void) loadAssetGroups {

        void (^assetGroupEnumerator)
        (ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) {
            NSLog(@"group....%@",[group valueForProperty:ALAssetsGroupPropertyName]);
            [self loadAssetForGroup:group];
            }
        };

        void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {
            NSLog(@"A problem occured. Error: %@", error.localizedDescription);
        };

        [[ImagePickerViewController defaultAssetsLibrary] enumerateGroupsWithTypes:ALAssetsGroupAll
                                     usingBlock:assetGroupEnumerator
                                   failureBlock:assetGroupEnumberatorFailure];


}

-(void) loadAssetForGroup:(ALAssetsGroup*)group {
    ALAssetsFilter *filter = [ALAssetsFilter allPhotos];
    [group setAssetsFilter:filter];
    __block NSMutableArray *indexes = [NSMutableArray arrayWithCapacity:0];

    [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if (result == nil)
        {
            return;
        }

        if (![self.allPhotos containsObject:result]) {

            [self.assets setValue:result forKey:[result valueForProperty:ALAssetPropertyURLs]];

            [self.allPhotos addObject:result];

            [indexes addObject:[NSIndexPath indexPathForItem:[self.allPhotos count]-1 inSection:0]];
            [self.collectionView performSelectorOnMainThread:@selector(insertItemsAtIndexPaths:) withObject:[NSArray arrayWithObject:[NSIndexPath indexPathForItem:self.allPhotos.count-1 inSection:0]] waitUntilDone:NO];
        }

    }];
}

从控制台我看到collectionView正在为前几个对象(在屏幕上可见)调用其dataSource方法cellForItemAtIndexPath,但我需要等待所有照片被读取,直到我看到collectionView刷新。

有没有办法让它“随时随地”运行?

0 个答案:

没有答案