If you have used Delphi, you should be clear about the frm file, that is, the file generated by the form that can be designed by dragging your mouse.
When using xcode for development, we also used the same form to design complex pages through simple drag and attribute settings, and then serialize them to the NIB file.ProgramWhen running, load it in.
During form development in xcode, NIB files are deserialized in two forms.
One is to set the NIB file attribute of the View Controller.
Another method is to use the initwithnibname method.
In fact, there is nothing to say, that is, reading the NIB file, loading, deserialization, generating instances, and displaying.
For the first type, there are some strange things in some places that cannot be understood.
Suppose you want to add a view for the main form window. The existing view-based template in xcode is to create a file with nib (assumed as myviewcontroller. the custom subclass of the uiviewcontroller (assuming myviewcontroller. m ).
Set the Class Name of the View Controller instance in mainwindow. XIB to the custom subclass myviewcontroller, and specify the NIB file as the NIB file (myviewcontroller. XIB) You just created ).
However, after testing, you only need to set the class and do not specify the NIB file.
Of course, if you use viewcontroller's superclass uiviewcontroller in delegate to define the property (the purpose of doing so is to enable mainwindow. plug the View Controller in the XIB and plug it into the outlet in the delegate). You can also specify only the NIB file to load it.
But what if I set the class name and NIB file to an unrelated class and NIB file?
The answer is mainly NIB file.
For example, we set the property of delegate to uiviewcontroller.
However, you can specify the class of View Controller in mainwindow. XIB as myviewcontroller1 (the corresponding NIB file is myviewcontroller1.xib)
However, if we set the NIB file of this view controller to myviewcontroller2.xib (the file owner is myviewcontroller2.m), the view in myviewcontroller2.xib is actually loaded.
In the design of mainwindow. in the XIB View Controller, in addition to loading other nib files, you can also directly design the view, that is, no other NIB file is required, directly in the mainwindow. XIB design.When the two are executed simultaneously, the form designed in mainwindow. XIB is used as the main part, that is, the form is not displayed even if other nib files are loaded.
This fast-food design is not required for people with cleanliness or severe self-obsessive-compulsive disorder.
That is, discard all nib files, and All Forms are designed inCode.
Transform the window-based template,
1. Delete the mainwindow. XIB file from the project.
2. Delete the main NIB file base name entry from info. plist.
3. Edit main. M.
Put this sentence
Java code
- Int retval = uiapplicationmain (argc, argv, nil, nil );
Int retval = uiapplicationmain (argc, argv, nil, nil );
Change
Java code
- Int retval = uiapplicationmain (argc, argv, nil, @ "___ projectnameasidentifier ___ appdelegate ");
Int retval = uiapplicationmain (argc, argv, nil, @ "___ projectnameasidentifier ___ appdelegate ");
4. Edit ___ projectnameasidentifier ___ appdelegate. m
Set the Method
Java code
- -(Void) applicationdidfinishlaunchinguiapplication *) Application {
- // Override point for customization after application launch
- [Window makekeyandvisible];
- }
-(Void) applicationdidfinishlaunchinguiapplication *) Application {// override point for customization after application launch [Window makekeyandvisible];}
Change
Java code
- -(Void) applicationdidfinishlaunchinguiapplication *) Application {
- Uiwindow * WD = [[uiwindow alloc] initwithframe: [uiscreen mainscreen] bounds];
- Self. Window = WD;
- [WD release];
- [Window makekeyandvisible];
- }
-(Void) applicationdidfinishlaunchinguiapplication *) Application {uiwindow * WD = [[uiwindow alloc] initwithframe: [uiscreen mainscreen] bounds]; self. window = WD; [WD release]; [Window makekeyandvisible];}
Of course, if you do not rewrite the template program, you can use the window-based template to generate the framework.
This article is transferred fromWww.35java.com