【问题标题】:UIImage:imageNamed on ipad fails ok in simulatorUIImage:ipad上的imageNamed在模拟器中失败
【发布时间】:2012-09-24 12:04:29
【问题描述】:

以下代码 sn-p 使用 iPad 模拟器和 iphone 模拟器可以正常工作。但是,当我在 ipad 2(使用 iphone 模式)上运行 UIImage 时,UIImage 为零(在调试时检查)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"flowerCell"];

    switch (indexPath.section) {
        case kRedSection:
            cell.textLabel.text=[self.redFlowers objectAtIndex:indexPath.row];
            break;

        case kBlueSection:
            cell.textLabel.text=[self.blueFlowers objectAtIndex:indexPath.row];
            break;

        default:
            cell.textLabel.text=nil;
    }

    NSString *img=[[NSString alloc] initWithFormat:@"%@%@", cell.textLabel.text, @".png"];

    UIImage *flowerImage=[UIImage imageNamed:img];

    cell.imageView.image=flowerImage;

    return cell;
}

这是一个来自教程书中的 billy 基本 iphone 示例,并且是第一次出现此问题。

【问题讨论】:

  • 错误信息是什么?您确定您的部分设置正确吗?
  • 图片是否包含在您的应用中,您是否检查过拼写?大写/小写?

标签: ios xcode cocoa-touch ipad ios-simulator


【解决方案1】:

尽量匹配图片名称小写-大写

如果图像名称是“image.png”并且您在代码中写入名称@“image.Png”,这将在模拟器上正常工作,而在设备上不起作用

【讨论】:

    【解决方案2】:

    我假设如果不是文件名大写,则图像丢失。

    模拟器可能通过缓存资源来掩盖问题。如果您从模拟器中删除应用程序,清理并再次运行,您可能会在模拟器上看到相同的问题。

    检查您的目标构建设置并查看图像是否在您的资源中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-25
      • 2021-11-01
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多