Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从用户照片库加载图像并更新UICollectionView_Ios_Objective C_Alassetslibrary - Fatal编程技术网

Ios 从用户照片库加载图像并更新UICollectionView

Ios 从用户照片库加载图像并更新UICollectionView,ios,objective-c,alassetslibrary,Ios,Objective C,Alassetslibrary,所以我有了UICollectionView。我需要从他的照片库中获取所有用户照片,并在照片加载时更新我的收藏视图。我尝试使用了NSNotificationCenter。我将observer添加到UICollectionViewController中,当我枚举照片时,我会发布通知,以便在加载照片时更新我的收集视图。这是我的控制器: 选择器方法: } 在[self.manager getPhonePhotos] 这就是我得到的错误: ***由于未捕获的异常“NSInternalInconsisten

所以我有了
UICollectionView
。我需要从他的照片库中获取所有用户照片,并在照片加载时更新我的收藏视图。我尝试使用了
NSNotificationCenter
。我将observer添加到
UICollectionViewController
中,当我枚举照片时,我会发布通知,以便在加载照片时更新我的收集视图。这是我的控制器:

选择器方法:

}

[self.manager getPhonePhotos]

这就是我得到的错误:

***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“一个视图上的更新动画太多-限制为一次运行31个(;};层=>)”


据我所知,当我列举照片时,我发布通知,然后执行通知方法,但
UICollectionView
没有制作动画。我数完后,他不知怎的开始了。那个么,在抓取照片时,我如何更新我的UI呢?有什么想法吗?

不要在照片枚举的每次迭代(每次调用块时)上发布通知。相反,构建一个包含所有资产的数组,并在块的最后一次调用中发布(IIRC,在最后一次调用中资产将为零,需要检查文档)


您当前的问题是,您每次发布通知都会启动大量动画,您应该整理所有更改,然后执行一个
performbatchUpdate

I,尽管我可以在从资产中逐个加载这些图像后使其显示。如果有很多照片呢?那是什么?这对用户来说会花费太多的时间,对吗?您是否在考虑资产加载和从资产加载图像之间的区别(我认为这是在不同的时间完成的,不记得100%)?您的错误表明资产加载很快,并且都在同一线程上。。。
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(phonePhotoLoaded:) name:@"PhonePhotoLoaded" object:nil];
    [self.manager getPhonePhotos];
-(void)phonePhotoLoaded:(NSNotification *)userInfo
{
[self.collectionView performBatchUpdates:^{
    NSDictionary *dic = [userInfo valueForKey:@"userInfo"];
    [self.photos addObject:[dic valueForKey:@"photo"]];
    [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:self.photos.count inSection:0]]];
} completion:^(BOOL finished){ 
}];
ALAssetsLibrary *al = [PhotoManager defaultAssetsLibrary];
[al enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
                  usingBlock:^(ALAssetsGroup *group, BOOL *stop){
                      [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
                          if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
                                  NSDictionary *userPhotos = [NSDictionary dictionaryWithObjectsAndKeys:asset, @"photo", nil];
                                  [[NSNotificationCenter defaultCenter] postNotificationName:@"PhonePhotoLoaded" object:self userInfo:userPhotos];
                          }
                      }];
     }failureBlock:^(NSError *error) {           
    ;}
 ];