Ios UICollectionView单元格中的UIImageView未显示

Ios UICollectionView单元格中的UIImageView未显示,ios,uiimageview,uicollectionview,xcode-storyboard,Ios,Uiimageview,Uicollectionview,Xcode Storyboard,我对iOS开发非常陌生,很抱歉发布了这样一个基本的错误,我只是无法理解这一点 我会告诉你到目前为止我做了什么,希望有人能在这里帮助我。到目前为止,我还没有编辑任何代码 添加集合视图控制器(单击并拖动到main.storyboard中) 在CollectionView的属性编辑器中配置单元格大小 将UIImageView对象拖到每个单元格上 将我的图像导入到项目中(将图像拖动到侧栏并导入) 选择每个UIImageView并在属性中选择正确的图像 完成此操作后,我的图像在脚本编辑器中完美显示,但当我

我对iOS开发非常陌生,很抱歉发布了这样一个基本的错误,我只是无法理解这一点

我会告诉你到目前为止我做了什么,希望有人能在这里帮助我。到目前为止,我还没有编辑任何代码

  • 添加集合视图控制器(单击并拖动到main.storyboard中)
  • 在CollectionView的属性编辑器中配置单元格大小
  • 将UIImageView对象拖到每个单元格上
  • 将我的图像导入到项目中(将图像拖动到侧栏并导入)
  • 选择每个UIImageView并在属性中选择正确的图像
  • 完成此操作后,我的图像在脚本编辑器中完美显示,但当我在模拟器中运行应用程序时,它只是一个带有指定背景颜色的空白屏幕


    ,您应该实现用于显示单元格的数据源方法。不测量是静态还是动态单元格

    您应该实现用于显示单元格的数据源方法。不测量是静态还是动态单元格

    您应该实现用于显示单元格的数据源方法。不测量是静态还是动态单元格

    您应该实现用于显示单元格的数据源方法。不测量是静态还是动态单元格

    您应该在创建集合视图控制器类后添加数据源方法

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

    您应该在创建集合视图控制器类后添加数据源方法

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

    您应该在创建集合视图控制器类后添加数据源方法

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

    您应该在创建集合视图控制器类后添加数据源方法

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


    您确定使用的是静态单元格而不是动态单元格吗?控制器不应实现数据源收集方法。您确定使用的是静态单元格而不是动态单元格吗?控制器不应实现数据源收集方法。您确定使用的是静态单元格而不是动态单元格吗?控制器不应实现数据源收集方法。您确定使用的是静态单元格而不是动态单元格吗?您的控制器不应实现数据源收集方法。谢谢您的帮助。但我不太明白-我是否创建了一个新类,它是集合视图控制器的子类,然后将代码放入它的.m文件中?我也需要为GalleryCell上课吗?是的,你说得对。。在gallery单元格中,为图像视图添加IBOutlet,并将其连接到collection view单元格中的图像视图。在cellForItemAtIndexPath方法中设置此映像,如上所述OK我已按照您的建议实现,但它引发了一个错误:
    由于未捕获异常“nsInternalInconsistenceException”而终止应用程序,原因:“无法将类型为的视图出列:标识符为XYZGalleryCell的UICollectionElementKindCell-必须为标识符注册nib或类,或连接情节提要中的原型单元格”
    在情节提要或nib中添加与cellForItemAtIndexPath中指定的标识符相同的单元格标识符,即GalleryCell检查此项谢谢你的帮助。但我不太明白-我是否创建了一个新类,它是集合视图控制器的子类,然后将代码放入它的.m文件中?我也需要为GalleryCell上课吗?是的,你说得对。。在gallery单元格中,为图像视图添加IBOutlet,并将其连接到collection view单元格中的图像视图。在cellForItemAtIndexPath方法中设置此映像,如上所述OK我已按照您的建议实现,但它引发了一个错误:
    由于未捕获异常“nsInternalInconsistenceException”而终止应用程序,原因:“无法将类型为的视图出列:标识符为XYZGalleryCell的UICollectionElementKindCell-必须为标识符注册nib或类,或连接情节提要中的原型单元格”
    在情节提要或nib中添加与cellForItemAtIndexPath中指定的标识符相同的单元格标识符,即GalleryCell检查此项谢谢你的帮助。但我不太明白-我是否创建了一个新类,它是集合视图控制器的子类,然后将代码放入它的.m文件中?我也需要为GalleryCell上课吗?是的,你说得对。。在gallery单元格中,为图像视图添加IBOutlet,并将其连接到collection view单元格中的图像视图。在cellForItemAtIndexPath方法中设置此映像,如上所述OK我已按照您的建议实现,但它引发了一个错误:
    由于未捕获异常“nsInternalInconsistenceException”而终止应用程序,原因:“无法将类型为的视图出列:标识符为XYZGalleryCell的UICollectionElementKindCell-必须为标识符注册nib或类,或连接情节提要中的原型单元格”
    在情节提要或nib中添加与cellForItemAtIndexPath中指定的标识符相同的单元格标识符,即GalleryCell检查此项谢谢你的帮助。但我不太明白-我是否创建了一个新类,它是集合视图控制器的子类,然后将代码放入它的.m文件中?我也需要为GalleryCell上课吗?是的,你说得对。。在gallery单元格中,为图像视图添加IBOutlet,并将其连接到collection view单元格中的图像视图。在cellForItemAtIndexPath方法中设置此映像,如上所述OK我已按照您的建议实现,但它引发了一个错误:
    由于未捕获异常“nsInternalInconsistenceException”而终止应用程序,原因:“无法将类型为的视图出列:标识符为XYZGalleryCell的UICollectionElementKindCell-必须为标识符注册nib或类,或连接情节提要中的原型单元格”
    在情节提要或nib中添加与cellForItemAtIndexPath中指定的标识符相同的单元格标识符,即GalleryCell检查此项链接