UIImage imageNamed returns nil

2020-01-24 23:08发布

I am pretty new to iOS and Xcode.

I tried to load an image with

[UIImage imageNamed:@"imageName.png/jpg and so on"];

but it only returns nil. The image should be in my project bundle, considering the fact that I can choose it from drag and drop menus in the InterfaceBuilder and it was added to Xcode via the "Add files to "projectname"..." menu.

It makes no difference whether I use .png or .jpg images, the result stays the same: they work via IB but not if I try to run the imageNamed method myself.

19条回答
兄弟一词,经得起流年.
2楼-- · 2020-01-24 23:40

In addition to @Inturbidus's answer: For those who came here working on Application Extensions:

The image you are working with should belongs to both targets - hosted app and extension.

In other case you'll always getting nil trying to access it from within the extension's code.

查看更多
登录 后发表回答