【发布时间】:2014-09-09 01:19:06
【问题描述】:
我有我的数据源方法
- (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、delegate 和 outlet 已连接
但是当我运行时,不会调用数据源方法,并且视图是纯白色的,没有 UICollectionView 显示。
编辑:改为以编程方式添加 uicollectionview。它显示但仍然没有单元格。
【问题讨论】:
-
这可能是一个愚蠢的问题,但数据源方法是在 Diary View Controller 中定义的吗?
-
你在哪里制作的单元格?除非您完全用代码(没有 xib 或情节提要)制作单元格,否则不应注册单元格类。
-
xcode 没有调用以上三种方法...?
-
@danh 是的。单元格是以编程方式制作的 - 没有 xib,只是 collectionview 的故事板,而不是单元格。日志没有显示他们被调用
-
你是否在IB中设置了“cell”作为cell标识符?
标签: ios uicollectionview