Ios UICollectionView未显示&;未调用委托/数据源方法

Ios UICollectionView未显示&;未调用委托/数据源方法,ios,uicollectionview,Ios,Uicollectionview,我有我的数据源方法 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return 10; } -(UICollectionV

我有我的数据源方法

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 10;
}

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

    LPDiaryCollectionViewCell *cell = (LPDiaryCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.testLabel.text = @"test";
    return cell;

}
该单元已注册

[self.collectionView registerClass:[LPDiaryCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
数据源、代理和出口已连接

但当我运行时,不会调用datasource方法,并且视图是纯白色的,没有显示UICollectionView


编辑:改为以编程方式添加uicollectionview。它显示但仍然没有单元格。

您必须在storybord中为集合视图单元格设置单元格标识符(例如,我已声明
identifier=“ReuseCell”
),并在cellForItemAtIndexPath方法中使用相同的情节提要标识符

static NSString *identifier = @"ReuseCell";        
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

静态NSString*标识符=@“Yourcellname”

UICollectionViewCell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:indexPath的标识符:indexPath]

这可能是一个愚蠢的问题,但数据源方法是在日记视图控制器中定义的吗?单元格是在哪里生成的?你不应该注册cell类,除非你完全在代码中创建了cell(没有xib或故事板)。xcode不调用上述三种方法中的任何一种…?@danh-Yup。单元格是以编程方式生成的-没有xib,只是collectionview的情节提要,而不是单元格。日志没有显示它们被调用。您在IB中是否已将“单元”设置为单元标识符?