Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImage "imageNamed:" works on iOS 8, but not 7?

There are several answers on SO already about "imageNamed:" not working, but none have included my particular wrinkle:

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. Is there some unusual behavior of asset catalogs on iOS 7 that has to be accounted for?

Here are some details, based on the answers to similar questions on this site:

  • This problem appears in actual builds that are archived and exported for users, as well as in the simulator. Both versions show the iOS 7/8 split in behavior.
  • Images are PNGs, and the Asset Catalog contains 1x, 2x, and 3x versions of each.
  • I've confirmed the spelling and capitalization matches (further confirmed by it working on iOS 8).

By far the majority of the answers on SO are for bugs that would prevent it from working at all. Can anyone help with an image call that only works on iOS 8?

like image 522
Nerrolken Avatar asked Nov 01 '22 04:11

Nerrolken


1 Answers

Huh. So apparently the solution was that if your imageset in the Asset Catalog has a file suffix within its name, iOS 7 gets tripped up. We've got several versions of each file in our Asset Catalog, the same image but for different uses, so my coworker had named them with the old filename like so:

"RedBall.png - Small" (includes 25px, 50px, 75px)
"RedBall.png - Large" (includes 150px, 300px, 450px)
"BlueBall.png - Small"
"BlueBall.png - Large"

Apparently iOS 8 is smart enough to recognize that "RedBall.png - Small" is the name, while iOS 7 doesn't know what to do when ".png" is right there in the middle.

Renaming the files to...

"RedBall - Small"
"RedBall - Large"
"BlueBall - Small"
"BlueBall - Large"

...seems to do the trick.

like image 81
Nerrolken Avatar answered Nov 15 '22 07:11

Nerrolken