【发布时间】:2015-04-21 10:27:37
【问题描述】:
我能够加载集合视图但无法加载单元格。下面是我正在使用的代码。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"reuseCell";
[self.view_dashboard registerClass:[UICollectionViewCell class]
forCellWithReuseIdentifier:@"reuseCell"];
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image= [UIImage imageNamed:[dashBoard_img objectAtIndex:indexPath.row]];
return cell;
}
【问题讨论】:
-
把
[self.view_dashboard registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"reuseCell"];这一行放在cellForItemAtIndexPath之外,你可以在viewDidAppear里面加进去 -
有注册笔尖文件吗?
-
你设置断点了吗? cellForItemAtIndexPath: 是否被调用?您不需要每次都为每个单元格注册课程。你只需要在你的 UIViewController 的其他地方调用一次。
-
是的,我在上面添加了行但是,我们无法加载单元格。@病毒
-
您是否实现了数据源协议?...还有...您是否将您的 collectionview 数据源委托设置为视图控制器?...还检查返回值:numberOfSectionsInCollectionView 和 numberOfItemsInSection
标签: ios objective-c iphone uicollectionview