Xcode bug:imagenamed: Method returns nil

Source: Internet
Author: User

Imagenamed: Method return nil often has the following situations:

  1. Item does not exist for this picture;

  2. The picture is not named correctly;

  3. There is a problem with the suffix of the picture (often using a. png image, a picture with a. jpg suffix may be problematic);

  4. The device is using a Retina screen, but the project does not provide a corresponding @2x image;


Excluding these common situations, my imagenamed: The method still returns nil.


Finally, uninstall the app from Simulator, Exit Simulator, close and restart the Xcode,clean project, recompile, run! The tragedy is still not good.


Is there something wrong with the editor? So I commented on the code and wrote it again on the next line.

UIImage *imageforbutton = [UIImage imagenamed:@ "Recharge"]; UIImage *imageforbutton = [UIImage imagenamed:@ "Recharge"];


It worked! The feeling was played by Xcode again.


My knowledge is relatively shallow, do not know the real reason for this problem is what, but if you also encounter this dilemma, may wish to try this method. Maybe Xcode is making fun of you.

This article is from "Happy coding ..." Blog, be sure to keep this source http://jiataozhou.blog.51cto.com/7355162/1684543

Xcode bug:imagenamed: Method returns nil

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.