Xcode 6 iOS 8 UIImage图像从捆绑问题命名 [英] Xcode 6 iOS 8 UIImage imageNamed from bundle issue

查看:118
本文介绍了Xcode 6 iOS 8 UIImage图像从捆绑问题命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用iOS 7.1构建我的项目并尝试使用存储在/images/cars/car_1.png中的图像加载UIImage视图

I build my project using iOS 7.1 and try to load UIImage view with image that is stored in the /images/cars/car_1.png

所有图像都位于在项目树中的下图中的文件夹图像中:

All images are located in the folder images as on picture below in project tree:

因此它适用于iOS 7.1和Xcode 5,但当我尝试使用Xcode 6和iOS 8时,UIImage实例等于零当我尝试箱子图像。

So it works perfect for iOS 7.1 and Xcode 5, but when I try to use Xcode 6 and iOS 8 the UIImage instance is equal nil when I try crate image.

UIImage *image = [UIImage imageNamed:@"/images/cars/car_1.png"];

po image

nil(适用于iOS 8)

nil (for iOS 8)

它也可以

UIImage *image = [UIImage imageNamed:@"/images/sport-cars/car_1.png"];

因为你可以看到资源的名称是相同的car_1.png但它没关系因为它们是在不同的资源文件夹中不在捆绑文件夹中。

as you can see the name of resources is the same car_1.png but it is ok because they are in different resources folders not in the bundle folders.

推荐答案

好的问题是在模拟器上并且在设备上也是如此由于某种原因,当我们使用 @/参考文件夹路径/ image.jpg时,它将无效。

Ok the problem is that on the simulator and seems on the device as well by some reason when we use @"/Reference Folder Path/image.jpg" it won't work.

在路径开头删除此/可解决此问题。

Removing this "/" at start of path solve this issue.

您可以查看视频,看看它是如何运作的。

You can check this video to see how it works.

这篇关于Xcode 6 iOS 8 UIImage图像从捆绑问题命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆