IPhone DevelopmentAboutNib fileThe description is the content to be introduced in this article. Let's talk about it in detail. A simpleIPhoneProject and code. You do not need to use Interface Builder to develop the iPhone program. a subtle difference is loadNibNamed: owner: options:
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.
In useXcodeDuring development, complex pages are designed through simple drag and attribute settings, and then serializedNib file.
InXcodeDuring form development, The Nib file is 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 and assume it is 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 that the class of View Controller in MainWindow. xib is MyViewController1, and its Nib file is MyViewController1.xib)
However, if we set the NIB File of this View Controller to MyViewController2.xib and its File Owner to 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 form designs are completed in the code.
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 Java code
- int retVal = UIApplicationMain(argc, argv, nil, nil);
- int retVal = UIApplicationMain(argc, argv, nil, nil);
Change to Java code
- int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppDelegate");
-
- int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppDelegate");
4. Edit ___ PROJECTNAMEASIDENTIFIER ___ AppDelegate. m
Java code
- - (void)applicationDidFinishLaunching:(UIApplication *)application {
-
- // Override point for customization after application launch
- [window makeKeyAndVisible];
- }
-
- - (void)applicationDidFinishLaunching:(UIApplication *)application {
-
- // Override point for customization after application launch
- [window makeKeyAndVisible];
- }
Change to Java code
- - (void)applicationDidFinishLaunching:(UIApplication *)application {
- UIWindow *wd = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- self.window = wd;
- [wd release];
- [window makeKeyAndVisible];
-
- }
-
- - (void)applicationDidFinishLaunching:(UIApplication *)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.
Summary:IPhone DevelopmentAboutNib fileI hope this article will help you!