[英]UIImageView in UICollectionView cells not displaying
I'm very new to iOS development, sorry for posting such a basic mistake, I just can't get my head around this. 我是iOS开发的新手,很抱歉发布这样的基本错误,但我还是无法解决。
I will tell you what I have done so far, hopefully someone can help me out here. 我会告诉你到目前为止我做了什么,希望有人可以在这里帮助我。 I have not edited any code so far. 到目前为止,我还没有编辑任何代码。
Having done this, my images display perfectly in the storyboard editor but when I run the app in the simulator it is just a blank screen with my specified background colour. 完成此操作后,我的图像可以在情节提要编辑器中完美显示,但是当我在模拟器中运行该应用程序时,它只是一个具有指定背景色的空白屏幕。
Screenshot of editor , Screenshot of simulator 编辑器的 截图,模拟器的截图
You should add the data source method after creating a collection view controller class, 您应该在创建集合视图控制器类之后添加数据源方法,
// Defines the number of cells in a section of collection view
- (NSInteger)collectionView:(UICollectionView *)cv numberOfItemsInSection:(NSInteger)section;
{
return numberOfItems;
}
// Defines the cells in the collection view
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
// Gallerycell is the custom collection view cell class holds the UIImage View
GalleryCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"GalleryCell" forIndexPath:indexPath];
// getting the image
cell.cellImage.image = [UIImage imageNamed:[dataSourceArray objectAtIndex:indexPath.row]];
return cell;
}
You should implement datasource methods for displaying a cell. 您应该实现用于显示单元格的数据源方法。 Doesn't meter if it's static or dynamic cells. 不测量是静态还是动态单元格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.