【问题标题】:UICollection View shows different results on Device than on Simulator集合视图在设备上显示的结果与在模拟器上不同
【发布时间】:2013-05-03 19:41:45
【问题描述】:

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

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

- (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;

}

【问题讨论】:

  • Retina 还是不是 Retina 设备?

标签: ios objective-c ipad uicollectionview


【解决方案1】:

以下是许多开发人员浪费时间的一个小细节:

区分大小写

真的,这一切都归结为:

  • iPhone 模拟器:大小写-不敏感
  • iOS 设备:大小写-敏感

因此,您的代码中可能包含“New Image.png”,但实际图像名称为“new image.png”。它甚至可能类似于“nEw iMaGe.png”。

这在模拟器上可以正常工作,但在设备上不行 - 设备根本找不到图像。

从图像到 plist 的所有事情都发生在我身上。

检查您的案例!

【讨论】:

  • 如果这不是问题的话。这比你建议的要微妙一些。实际文件名为 New image.png。我得小心那个。感谢您的帮助!
【解决方案2】:

我遇到了类似的问题,但罪魁祸首是网络延迟 - 必须手动调用 self.collectionView.reloadData() 才能显示。在本地,数据加载速度显然足够快,这不是问题。

【讨论】:

    猜你喜欢
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    相关资源
    最近更新 更多