问题描述
我正在尝试使UICollectionView在我的应用程序中正常工作,由于某种原因,我一直在获取sigabrt.我收到的错误是
I'm trying to get a UICollectionView working in my application and for some reason I keep getting a sigabrt. The error I am getting is
* -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]中的断言失败
* Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]
我已经四处搜寻,似乎在大多数情况下这与对registerClass forCellWithReuseIdentifier的忽略有关,但是我在视图加载方法中按要求进行此操作.我的代码如下:
I have googled around, and it seems like most of the time this is related to the neglecting to registerClass forCellWithReuseIdentifier, but I am doing this as required in the view did load method. My code is as follows:
- (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;
}
有人知道我可能会想念什么吗?
Does anyone know what I might be missing?
推荐答案
一个单元格标识符是"Cell"&另一个是单元格".即单元格后的多余空间,将其删除.
one cell identifier is "Cell" & another one is "Cell ". i.e. extra space after cell, remove it.
这篇关于dequeueReusableCellWithReuseIdentifier上的iOS SIGABRT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!