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 folderGroup
The 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.