<分区>
我正在尝试让 UICollectionView 在我的应用程序中工作,但出于某种原因,我不断收到 sigabrt。我得到的错误是
* -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:] 断言失败
我用谷歌搜索了一下,似乎大多数时候这与忽略 registerClass forCellWithReuseIdentifier 有关,但我是按照 View did 加载方法中的要求执行此操作的。我的代码如下:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
[self.collectionView reloadData];
self.refreshControl = [[UIRefreshControl alloc]init];
[self.collectionView addSubview:self.refreshControl];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Cell " forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
有谁知道我可能遗漏了什么?