Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView没有resuseIdentifier错误_Ios_Xcode6_Uicollectionview - Fatal编程技术网

Ios UICollectionView没有resuseIdentifier错误

Ios UICollectionView没有resuseIdentifier错误,ios,xcode6,uicollectionview,Ios,Xcode6,Uicollectionview,代码: 我以编程方式创建UICollectionView。我已经做了布局和登记的一切。它抛出错误作为 “NSInternalInconsistencyException”,原因:“从-collectionView:cellForItemAtIndexPath:返回的单元格没有reuseIdentifier-必须通过调用-dequeueReusableCellWithReuseIdentifier:forIndexPath:'检索单元格。” 我仔细检查了我的代码。我缺少什么?您的表视图单元格应该从

代码:

我以编程方式创建UICollectionView。我已经做了布局和登记的一切。它抛出错误作为

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


我仔细检查了我的代码。我缺少什么?

您的表视图单元格应该从
dequeueReusableCellWithIdentifier:forIndexPath:
方法初始化,并且您应该将属性设置为使用此方法出列的单元格

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

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;
}

您只需修改您的
initWithWidth:…
,使其成为一个“设置方法”,并在单元格出列后调用它来设置标签和图像。

如果已经出列,为什么要重新初始化单元格?我在该方法中创建了标签、图像和按钮。。
MSShulListCollectionCell *cell = (MSShulListCollectionCell *)[m_collectShulList dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

cell.width = ...;
cell.height = ...;
cell.name = ...;