ios - Collection View 在设备上显示的结果与在模拟器上不同

标签 ios objective-c ipad uicollectionview

我试图弄清楚以下代码段中可能发生的情况。我有一个收藏 View ,我将保存的图像显示为缩略图。我还在末尾插入了一个股票“新图像”图标,以便用户可以添加额外的图像。

在 iPad 模拟器上它看起来很好,但是当我在设备上运行时,我没有看到“新图像”图标。我可以触摸它以打开相机 View Controller 进行捕获/选择,但图像不显示。有任何想法吗?这是代码...

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

static NSString *cellIdentifier = @"cvCell";

CVCell *cell = (CVCell *)[[self sectionImagesCollectionView] dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
if ([indexPath row] < [sectionImages count]){
    // Have an image so assign the photograph
    RFHSectionImages *sectionImage = [sectionImages objectAtIndex:[indexPath row]];
    UIImage *image = [UIImage imageWithData:[sectionImage photograph]];
    [[cell imageView] setImage:image];
} else {
    // Use the standard image
    UIImage *newPhoto = [UIImage imageNamed:@"New Image.png"];
    [[cell imageView] setImage:newPhoto];
}

return cell;

}

最佳答案

这是许多开发人员浪费时间的一个小细节:
区分大小写
真的,这一切都归结为:

  • 手机 模拟器 : 案例- 不敏感
  • iOS 设备 : 案例- 敏感

  • 因此,您的代码中可能有“New Image.png”,但实际的图像名称是“new image.png”。它甚至可能类似于“nEw iMaGe.png”。
    这在模拟器上可以正常工作,但是 不是 在设备上 - 设备根本找不到图像。
    从图像到 plist 的所有事情都发生在我身上。
    检查您的案例!

    关于ios - Collection View 在设备上显示的结果与在模拟器上不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16366390/

    相关文章:

    ios - 如何在与 OpenGL 混合的 GLKView 中绘制字符串

    ios - 在显示然后隐藏 UIView 覆盖层后,UIWebView 屏幕点击区域停止工作

    iphone - iOS 文件下载

    ios - 带主键的多对一(唯一约束)

    ios - SwiftUI 允许 Struct 中的所有字符串枚举

    objective-c - iPad 横向发布

    ios - 我可以不显示UILocalNotification吗?

    ios - 有没有可能使用文件名从库中获取照片?

    ios - 如何设置被UIBezierPath整形的CAShapeLayer的内容

    iphone - 如何使用 UIPanGestureRecognizer 移动对象? iPhone/iPad