The image path is null.

Source: Internet
Author: User

The image path is null.
_ 1. Problem description :_

In use
NSString * path = [[NSBundle mainBundle] pathForResource: picName ofType: nil];
When obtaining the absolute path of an image, the obtained path is null, that is, the path acquisition fails. The running prompt is similar to the following exception:
[Cocould not load<Image name>Image referenced from a nib in the bundle with identifier<Project Name>]
As a result, the image cannot be added to the array through the image path, prompting that the empty object cannot be added.

_ 2. Problem Analysis :_

Original article: http://blog.csdn.net/u012945598/article/details/17955215
The problem lies in the Process of importing images to the project. When you drag the image folder into Xcode, there will be two Added folders options:
Bytes

Create groups
Create folder references
If you select the first method to add a file, we will find the added file, the folder is yellow
The second method is selected. The folder of the file to be added is blue.

What are the differences between the two methods?

1. Use Create groups to Create any newly added folderGroupThe Group concept may not be unfamiliar. You can manually add a Group in the project (right-click and choose New Group ), however, the manually added groups does not actually exist in the project directory. You will find that the files added to the groups are still in its original location, but the groups introduced from the outside is not like this, as we did just now. Once a groups object is created or added, it is in the form of a yellow folder. When you want to use the header file of a class in the folder, you can directly add its reference, for example
'# IncludeXxx. h
This is because the cpp file under groups will be compiled.

2. the Create folder references method is used to Create reference files, which are not compiled. Therefore, you need to add the file path when using it, for example, if we want to use a header file under the myScripts folder, we need to add the declaration as follows:
'# IncludeMyScripts/xxx. h
Otherwise, the compiler will tell you that the xxx. h file cannot be found.

This is the difference between the yellow folder and the blue folder in the project and how to use it.

As for the Destination option, if you select this option, if the file you want to introduce is not in the directory of your project file, xcode automatically copies the file to the directory of your project.
If you do not select the file and the file is not in your project directory, the file can still be used, but once you copy the project to another place, this file cannot be found. Because this file is on your computer, not in your project.

_ 3. Solution :_

When adding an image file, select the first option Crest groups to compile it.

Related Article

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.