1, [NSBundle Mainbundle], the folder is actually group, such as the left side of the tree file Manager
After the build, the file is copied directly to the root directory, so the Read method should be:
NSString*earth = [[NSBundle mainBundle] pathForResource:@"Brad Cox"ofType:@"png"]; |
2, when using the folder, build results
Still use the same method, do not need to set the folder path
Indirectory parameters are optional
NSString *earth = [[NSBundle mainbundle] pathforresource:@ "Matthijs" oftype:@ "png" indirectory:@ "Images/MoreImages"]; NSString *earth = [[NSBundle mainbundle] pathforresource:@ "Matthijs" oftype:@ "PNG"];
After compiling, mainbundle resources are placed under RootFolder, so you can access them directly, not specify the internal path
3. Use other bundles
NSString *resourcebundle = [[NSBundle mainbundle] pathforresource:@ "Resources" oftype:@ "bundle"]; NSLog (@ "ResourceBundle:%@", resourcebundle);
Using the custom bundle to access the internal subfolders, you need to specify the Indirectory parameter, this mainbundle is different, why?
Note: Sincebundles other than the main bundle can has folders embedded inside them, to accessfiles inside folders of a Bundl e other than the main bundle it's best for use the pathForResource:ofType:inDirectory:method of NSBundle to explicitly SP Ecify the folder Inwhich a specific file/resource exists.
Original address: http://www.cnblogs.com/iihe602/archive/2013/01/17/2865280.html
IOS NSBundle Use, note the difference between mainbundle and custom bundles