在尝试从我的集合视图中卸载一批图像然后用另一批替换它们的过程中,我遇到了一个错误,根据原始图像或后续图像组是否多于或少于预期的替换,发生断言错误,其中说:
*** Assertion failure in -[UICollectionViewData validateLayoutInRect:],
/SourceCache/UIKit_Sim/UIKit-2891.1/UICollectionViewData.m:341
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'UICollectionView recieved layout attributes for a cell with an
index path that does not exist: <NSIndexPath: 0xb141c60> {length = 2, path = 0 - 2}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,现有的图像计数列表为5,新的图像列表计数为2.因此,当它到达第三个图像时 - 发生异常 - 表示UI CollectionViewDataDelegate不知道数据流中的更改.
有关如何确保UICollectionView引用新图像的任何建议?当然我叫'reloadData'......
谢谢
我在UICollectionView中遇到了一个奇怪的崩溃.崩溃的UICollectionView嵌入在另一个UICollectionView的UICollectionView单元格中.
我无法重现这个问题,有时如果内部UICollectionView得到新的初始化,因为外部CollectionView正在重新加载它的单元格.
com.apple.main-thread Crashed 0 libobjc.A.dylib objc_msgSend + 9 1 UIKit -[UICollectionViewData _setLayoutAttributes:atGlobalItemIndex:] + 60 2 UIKit __45-[UICollectionViewData validateLayoutInRect:]_block_invoke_0 + 668 3 UIKit -[UICollectionViewData validateLayoutInRect:] + 1408 4 UIKit -[UICollectionViewData layoutAttributesForElementsInRect:] + 82 5 UIKit -[UICollectionView setCollectionViewLayout:animated:] + 1644 6 MyApp BSCTopnewsCollectionView.m line 52 -[BSCTopnewsCollectionView setupBSCTopnewsCollectionView] 7 MyApp BSCTopnewsCollectionView.m line 27 -[BSCTopnewsCollectionView setWeakDelegatePointer:] 8 Myapp BSCFrontPageViewController.m line 550 -[BSCFrontPageViewController collectionView:cellForItemAtIndexPath:] 9 UIKit -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:] + 252 10 UIKit -[UICollectionView _updateVisibleCellsNow:] + 2672 11 UIKit -[UICollectionView layoutSubviews] + 214 12 UIKit …
使用IOS 6和新的UICollectionView我在UIViewController上有2个UICollectionView并使用Storyboard当我点击UICollectionView时我得到以下错误我不知道为什么会发生这种情况并且Google返回0结果这个错误...
2012-10-13 20:30:06.421 MyApp [768:907]断言失败 - [UICollectionViewData numberOfItemsBeforeSection:],/ SourceCache/UIKit/UIKit-2372/UICollectionViewData.m:415
2012-10-13 20:30:06.427 MyApp [768:907]由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'当在集合视图中只有1个部分时,请求部分2147483647之前的项目数'
我根本没有使用Sections,只将它设置为1个部分:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
Run Code Online (Sandbox Code Playgroud)
当我点击UICollectionView区域时,它会发生(似乎是随机的)我有一段代码从UICollectionView中删除元素:
[tilesArray removeObjectAtIndex:indexPath.row];
[self.tilesCollectionView reloadData];
[resultsArray addObject:str];
[self.resultsCollectionView reloadData];
Run Code Online (Sandbox Code Playgroud)
以下是数组如何连接到UICollectionViews
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if(collectionView.tag == 2)
return [resultsArray count];
else
return [tilesArray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if(collectionView.tag == 2)
{
static NSString *cellIdentifier = @"ResultCell";
ResultCell *cell = (ResultCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.mainImage.image = [UIImage imageNamed:currentArtContainer.tileMainImage];
NSString *cellData = [resultsArray objectAtIndex:indexPath.row];
[cell.titleLabel setText:cellData]; …Run Code Online (Sandbox Code Playgroud)