使用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)