【发布时间】:2015-05-03 17:03:13
【问题描述】:
我有一个 uitableview,其中嵌套了一个集合视图。 Collectionview 和 Tableview 都只有 1 个部分。在 collectionview 单元格中有 uiimageviews。我正在从服务器下载图片,下载图片后,我想在图像视图中显示它们。我正在调用 reloadItemsAtIndexPaths 来重新加载单元格的内容以显示图片。这是我目前发现的:
如果我正在使用
[NSIndexPath indexPathWithIndex:[secondArray indexOfObject:dictionaryToRefresh]]
作为 reloadItemsAtIndexPaths 中要刷新的索引,然后第一张图片在集合视图的第一个单元格中加载得很好。 reloadItemsAtIndexPaths 也有很好的淡入效果。然后它因错误而严重崩溃:
-[UICollectionView 中的断言失败 _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /SourceCache/UIKit/UIKit-3347.44/UICollectionView.m:3835 2015-05-03 18:47:02.385 FBomb[3117:798045] *** 由于以下原因而终止应用程序 未捕获的异常“NSInternalInconsistencyException”,原因: '尝试删除第 1 节,但在第 1 节之前只有 1 节 更新”
如果我使用
[NSIndexPath indexPathForItem:[secondArray indexOfObject:dictionaryToRefresh] inSection:0];
所有图片加载都很好!但是没有淡入效果,这是我想要实现的。关于我可以克服这个问题的任何想法?我想显示带有淡入效果的图片(我真的不明白为什么它不会发生)
提前致谢,请原谅拼写错误!
编辑1 完整代码:
-(void) reloadItemWithDictionary:(NSDictionary*)dictionaryToRefresh{
BOOL dictionaryFound = FALSE;
NSIndexPath *= [[NSIndexPath alloc]init];
NSIndexPath *indexPathSecondArray = [[NSIndexPath alloc] initWithIndex:0];
for (NSDictionary *firstDictionary in megaArray)
{
NSArray *secondArray = [firstDictionary objectForKey:@"subArray"];
if ([secondArray containsObject:dictionaryToRefresh]){
indexPathFirstArray = [NSIndexPath indexPathForRow:[megaArray firstDictionary] inSection:0];
//THIS FADES THE FIRST ITEM ONLY, THEN CREASHES
//indexPathSecondArray = [NSIndexPath indexPathWithIndex:[secondoArray indexOfObject:dictionaryToRefresh]];
//THESE WORKS, BUT THEY DON'T FADE
indexPathSecondArray = [NSIndexPath indexPathForItem:[secondoArray indexOfObject:dictionaryToRefresh] inSection:0];
//indexPathSecondArray = [NSIndexPath indexPathForRow:[secondoArray indexOfObject:dictionaryToRefresh] inSection:0];
dictionaryFound = TRUE;
break;
}
}
if ( dictionaryFound == TRUE){
dispatch_sync(dispatch_get_main_queue(), ^{
UITableViewCell *tableCell = [tableWithCollectionView cellForRowAtIndexPath:indexPathFirstArray];
UICollectionView *collectionViewInTableCell = (UICollectionView *)[tableCell viewWithTag:1000];
[collectionViewInTableCell performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:@[indexPathSecondArray]];
} completion:^(BOOL finished){
}];
});
}
}
【问题讨论】:
-
看起来很好地淡入图片的唯一方法是调用 collectionView reloadSections 而不是 collectionView reloadItemsAtIndexPath....
-
所以基本上
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];为你工作? -
它可以工作,但当然是重新加载整个部分,这不是我想要的。不过,我还没有找到其他解决方案...
标签: ios objective-c uitableview uicollectionview