IOS Resource Management

Source: Internet
Author: User
Specified device Resource

The file name format is as follows:
<Basename> <device>. <filename_extension>
<Basename> indicates the original name of the resource file and the name of the file accessed by the Code;
<Filename_extension> is the standard file extension;
<Device> indicates the modifier specified by the device:
~ IPad: only available on iPad devices
~ IPhone: only on iPhone or iPod Touch devices.
Resource loading route:
If the specified resource does not exist, the system searches for the resource file named after the original file name.

String Resource

Create a string resource file
1. Select the string to be localized
2. Loading macros with strings
Core Foundation macro:
Cfcopylocalizedstring
Cfcopylocalizedstringfromtable
Cfcopylocalizedstringfromtableinbundle
Cfcopylocalizedstringwithdefaultvalue
Foundation macro:
Nslocalizedstring
Nslocalizedstringfromtable
Nslocalizedstringfromtableinbundle
Nslocalizedstringwithdefaultvalue
The preceding macro gets the string value corresponding to the current user's language preferences. In addition, the genstrings tool searches for these macros to construct string files.
3. Use the genstrings command line tool to create a string File
Genstrings-o en. lproj *. m
-O parameter specifies the output file
*. M specifies the wildcard character of the source code file name.
Format String Resources
Use N $ to reference the placeholder at the specified position in the source string
/* Message in alert dialog when something fails */
"% @ Error! % @ Failed! "=" % 2 $ @ blah, % 1 $ @ blah! ";
Use special characters in string Resources
Escape Character \
Unicode Character \ uxxxx (must be passed to the genstrings tool-u parameter)
Debug string Resources
Plutil-Lint

Images, sounds, and editing resources

The format of IOS 4.0 high-resolution image files is as follows:
<Basename> @ 2x. <filename_extension>
Note: @ 2x modifier should be after any device modifier, other modifier (Direction, URL mode.

NIB Resources

List of NiB files
Interface object
An interface object is an element that is added to the interface builder document to implement the user interface. When a NIB file is loaded at runtime, the interface object is the object actually created by NIB to load the code.
File's owner
The file's owner object is a proxy object instead of being created when the NIB file is loaded. Instead, you need to create and pass the code to the nib loaded code in your own code. The importance of this object is embodied in its main connection between application code and NIB file content. Specifically, it is the control object responsible for the content of the NIB file.
First responder
The first responder object is a proxy object, indicating the first object of the responder chain dynamically determined by the application. Because the application's responder chain cannot be determined at design time, the first responder proxy serves as an alternative target for receiving behavior messages in the responder chain.
Top-level objects
The top-level object is an object without a parent object in the object graph after the NIB file is loaded. File's owner, first responder, and application objects are proxy objects, not top-level objects.
Load nib files
Load Using nsbundle
-(Nsarray *) loadnibnamed :( nsstring *) Name owner :( ID) Owner options :( nsdictionary *) options;
The owner parameter is the file's owner object.
Returns an array of top-level objects.
Load through uiviewcontroller
-(ID) initwithnibname :( nsstring *) nibname bundle :( nsbundle *) nibbundle;
The file's owner object is the uiviewcontroller object itself.

NIB Document Design Guide
Delayed loading-The NIB file only contains objects that are immediately referenced, rather than objects that are referenced when the load is complete and placed in another NIB file until it is actually referenced.

NIB object Lifecycle
Loading Process
1. Load the content of the NIB file and all referenced resources to the memory
● Load the original data of the entire nib object graph archived
● Load all associated custom image resources and add them to the image Cache
● Load all associated custom sound resources and add them to the sound cache (does IOS have it ?)
2. archive the object graph and initialize the object
● Standard IB objects (including the objects of subclass of the classes of these objects) are initialized through initwithcoder:
In iOS, any object implementing the nscoding protocol is initialized through initwithcoder: method, including uiview, uiviewcontroller, and its subclass.
● Other custom objects are initialized using the init method.
3. Create a connection (including action, outlet, and binding) between objects in all nib files)
● Outlet connection
IOS reconstructs the outlet connection using the setvalue: forkey: method and generates a KVO notification.
● Action connection
IOS uses addtarget: Action: forcontrolevents: To prepare the action. If the target is nil, the action will be processed by the responder chain.
● Binding
Not supported by IOS
4. The order of sending an awakefromnib message to the corresponding object cannot be guaranteed. IOS does not send this message to the file's owner, first responder, and other proxy objects.
5. display all "visible at launch time" as real windows.

Built-in support for NiB files
You can use the nsmainnibfile keyword in the info. plist file to specify the application to load the NIB file in the main window.

Replace proxy object during loading
The proxy object indicates the object that is connected to the content of a single NIB file created outside the NIB file.
-(Void) applicationdidfinishlaunching :( uiapplication *) Application {
Nsarray * toplevelobjs = nil;
Nsdictionary * proxies = [nsdictionary dictionarywithobject: Self forkey: @ "appdelegate"]; // tags in the NIB file
Nsdictionary * Options = [nsdictionary dictionarywithobject: proxies forkey: uinibexternalobjects];

Toplevelobjs = [[nsbundle mainbundle] loadnibnamed: @ "Main" Owner: Self options: Options];
If ([toplevelobjs count] = 0 ){
Nslog (@ "warning! Cocould not load mynib file. \ n ");
Return;
}

// Show window
[Window makekeyandvisible];
}

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.