About Nib files in iPhone Development

Source: Internet
Author: User

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

 
 
  1. int retVal = UIApplicationMain(argc, argv, nil, nil);    
  2. int retVal = UIApplicationMain(argc, argv, nil, nil); 

Change to Java code

 
 
  1. int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppDelegate");    
  2.  
  3. int retVal = UIApplicationMain(argc, argv, nil, @"___PROJECTNAMEASIDENTIFIER___AppDelegate"); 

4. Edit ___ PROJECTNAMEASIDENTIFIER ___ AppDelegate. m

Java code

 
 
  1. - (void)applicationDidFinishLaunching:(UIApplication *)application {         
  2.     
  3.     // Override point for customization after application launch     
  4.     [window makeKeyAndVisible];     
  5. }    
  6.  
  7. - (void)applicationDidFinishLaunching:(UIApplication *)application {      
  8.  
  9.     // Override point for customization after application launch  
  10.     [window makeKeyAndVisible];  

Change to Java code

 
 
  1. - (void)applicationDidFinishLaunching:(UIApplication *)application {     
  2.     UIWindow *wd = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];     
  3.     self.window = wd;     
  4.     [wd release];     
  5.     [window makeKeyAndVisible];     
  6.     
  7. }    
  8.  
  9. - (void)applicationDidFinishLaunching:(UIApplication *)application {  
  10.     UIWindow *wd = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  11.     self.window = wd;  
  12.     [wd release];  
  13.     [window makeKeyAndVisible];  
  14.  

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!

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.