UICollectionView没有resuseIdentifier错误

时间:2015-07-13 06:21:24

标签: ios xcode6 uicollectionview

代码:

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake([GRAPHICS SCREEN_WIDTH], 160);
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

m_collectShulList = [[UICollectionView alloc]initWithFrame:CGRectMake(0, (m_imgBottomView.frameX + 160), [GRAPHICS SCREEN_WIDTH], 160) collectionViewLayout:layout];

[m_collectShulList setDataSource:self];
[m_collectShulList setDelegate:self];
[m_collectShulList setBackgroundColor:[UIColor clearColor]];
[m_collectShulList setPagingEnabled:YES];

[self.m_bgImageView addSubview:m_collectShulList];
[m_collectShulList registerClass:[MSShulListCollectionCell class] forCellWithReuseIdentifier:@"cellIdentifier"];

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"cellIdentifier";
    MSShulListEntity *entity = [m_arrShulList objectAtIndex:indexPath.row];
    MSShulListCollectionCell *Cell = (MSShulListCollectionCell *)[m_collectShulList dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

    Cell = [[MSShulListCollectionCell alloc]initWithWidth:[GRAPHICS SCREEN_WIDTH] withHeight:160.0 withName:entity.strShulName withAddress:entity.strShulAddress withPhone:entity.strShulPhone withSchedule:entity.strShulShedule withLikeCount:entity.strShulLikeCount];

    Cell.backgroundColor=[UIColor clearColor];
    Cell.contentView.backgroundColor = [UIColor clearColor];    

    return Cell;
}

我以编程方式创建UICollectionView。我已经完成了布局并注册了所有内容。它会抛出错误

  

“NSInternalInconsistencyException”,原因:'从-collectionView:cellForItemAtIndexPath:返回的单元没有reuseIdentifier - 必须通过调用-dequeueReusableCellWithReuseIdentifier来检索单元格:forIndexPath:'“。

我仔细检查了我的代码。我错过了什么?

1 个答案:

答案 0 :(得分:0)

您的表格视图单元格应该从rescue_from AppnexusApi::Error do |exc| respond_to do |format| if exc.message.include?("NOAUTH") elsif exc.message.include? "UNAUTH" elsif exc.message.include? "SYNTAX" elsif exc.message.include? "SYSTEM" elsif exc.message.include? "INTEGRITY" else end end end 方法初始化,您应该将属性设置为使用此方法出列的单元格。

因此,尝试将您的委托方法实现为

dequeueReusableCellWithIdentifier: forIndexPath :

您只需修改MSShulListCollectionCell *cell = (MSShulListCollectionCell *)[m_collectShulList dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; cell.width = ...; cell.height = ...; cell.name = ...; 并将其设置为“设置方法”即可。并在细胞出列后调用它来设置标签和图像。