UIImage imageNamed returns nil

uiimage imagenamed swift
uiimage imagenamed objective c
uiimage imagenamed:inbundle
uiimage metadata
uiimage symbol
uiimage(named)
uiimage import
set uiimage to nil swift

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.

imageNamed:, + (UIImage *)imageNamed:(NSString *)name; Return Value. An object containing an unconfigured version of the image, or nil if the method could not find the� UIImage imageNamed returns nil. 602. Xcode 6 Bug: Unknown class in Interface Builder file. 289. UIActivityViewController crashing on iOS 8 iPads. 759.

Re Mike Weller's comment. The checkbox is ....

ios UIImage imageNamed returns nil?, ios UIImage imageNamed returns nil? I didn't change anything in code at all so there was definitely something wrong with the actual image file. I� There are only a few reasons why an image would come back nil with imageNamed: The image is not in your bundle. Make sure the image is actually in your project. Make sure the target is checked by clicking on the file and selecting the target it belongs to. You have the image name spelled incorrectly or a problem with the extension.

In my case, the PNG was malformed.

For some reason Xcode preview shown it correctly, but when I tried loading it with UIImage, it returned nil.

UIImage imageNamed returns nil, 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,� I'm getting nil from "imageNamed:" on iOS 7, but the same build works on iOS 8. Obviously, everything is hooked up properly because it does work on iOS 8, but it consistently returns nil for a wide range (maybe 2 dozen) of images on iOS 7. Notably, I moved the assets to an AssetCatalog around the time this started.

I just had this issue for jpg files named on disk "file.jpg"

I was trying to load without the extension, just @"file". While this works fine for pngs, it does not for jpg. Once I used @"file.jpg", it worked!

UIImage imageNamed returns nil, [UIImage imageNamed:@"imageName.png/jpg and so on"];. but it only returns nil . The image should be in my project bundle, considering the� Return Value. An object containing an unconfigured version of the image, or nil if the method could not find the specified image.

If you verified all of the above and are finding that your UIImage(named: "myImage") returns nil from code inside of a dynamic framework you are building, then you have to change the code to:

UIImage(named: "myImage", in: Bundle(identifier: "com.myframework.name"), compatibleWith: nil)

This should retrieve the asset from CXAssets correctly.

UIImage imageNamed returns nil, 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� Return Value The image object that best matches the desired traits with the given name, or nil if no suitable image was found.

Loading images with UIImage, That's where if let is clever: if any of those things return nil (i.e., they fail), then the Instead, UIImage is the data type you'll use to load image data, such as PNG� Swizzled UIImage imageNamed for iPhone 5. GitHub Gist: instantly share code, notes, and snippets.

关于ios:UIImage imageNamed返回nil, UIImage +imageNamed:inBundle:compatibleWithTraitCollection: returns nil for resource bundles containing compiled asset catalogs� You use image objects to represent image data of all kinds, and the UIImage class is capable of managing data for all image formats supported by the underlying platform. Image objects are immutable, so you always create them from existing image data, such as an image file on disk or programmatically created image data.

rdar://24056523: UIImage +imageNamed:inBundle , [framework] CUICatalog: Invalid asset name supplied: '(null)'. This appears to be caused by calling +[UIImage imageNamed:] with a nil string. UIImage* img = [UIImage imageNamed:backgroundImageFilename]; if (img != nil) { //The image loaded fine (this always worked before). Job done. //We'll set our UIImageView "imgBackgroundView" to contain this image.

Comments
  • Select the file, and open the File Inspector pane on the right. Make sure there is a checkmark next to your target.
  • Have you tried cleaning your project yet? Shift-Apple-K is the command. that seemed to be the main reason I lost images.
  • tried cleaning as my first idea already. Can't find any checkmark in the File Inspector, where exactly should it be?
  • ah, now i know what Mike Weller meant: yes there is a checkmark next to my project
  • can you edit the question and put in the exact code you are using to get the image please?
  • Sry for my late answer - I was sick and just got back to work today. I tried rewriting and recompiling the code and suddenly it worked! I am still not exactly sure as about why it does/didn't before, but thanks a lot for all the help!
  • I had to delete the app, but that alone did not fix the problem. After doing product -> clean, I was able to see the correct images
  • You are 100% right! I had the same problem and it was because I didn't have the @2x file.
  • Haven't had any .jpg files in my bundle for like... ever? Copied one for testing purposes, lost prolly a half an hour wondering why my image wasn't loading. Up vote for bringing up the .jpg extension problem - even though I figured it out myself.
  • It seems that iOS 7 has a problem with JPG images while iOS 8 doesn't so it happened to me and fixed it by converting the images into PNG
  • thanks a lot, found that myself after rereading the comment. It is checked though and sadly does not change the behaviour.
  • You save my day! I ran into similar situation by changing image file extension from .psd to .png and expect it to work as proper png file.. Somehow Xcode lets me preview the image correctly.. That's evil
  • Just had the same issue. The original file was a JPEG which was re-saved as a PNG. On the simulator it worked fine but on an actual device the image would always return nil.