Ios_init Related Information

Source: Internet
Author: User

First, Initwithnibname This method is created in the Controller's class in IB, but it is used when instantiating a controller through Xcode.
Second, Initwithcoder is called when a class is created in IB but is instantiated in XOCDE. For example, create a controller's nib file with IB and then in Xcode Initwithnibname to instantiate the controller, the controller's initwithcoder will be called. Or a view nib file that is called when the method is created Initwithcoder
Third, awakefromnib

When the. nib file is loaded, a awakefromnib message is sent to each object in the. nib file, and each object can define its own awakefromnib function to respond to the message and perform some necessary actions. That is, the awakefromnib is executed when the view object is created from the nib file
Iv. the differences and linkages between initwithnibname and loadnibnamed:

About the difference and connection between Initwithnibname and loadnibnamed. I think I'm a little confused about what I'm going to do with the two. Actually figuring out the difference between them will not be so confused. Because these two methods are not tarred with at all.
Since it is to illustrate these 2 methods, then focus on the difference.
But the first step is to wordy, their connection: You can use this method to load the user interface (Xib file) into our code, so that you can manipulate the loaded (Xib) object to operate the Xib file content.
The following goes into the topic, talking about the difference:
1. Initwithnibname Method of Showviewcontroller
Showviewcontroller * ShowMessage = [[Showviewcontroller alloc]
initwithnibname:@ "Showviewcontroller" bundle:nil];
Self.showviewcontroller = ShowMessage;
[ShowMessage release];
The Loadnibnamed method of 2.VideoCellController
Nsarray * nib = [[NSBundle mainbundle] loadnibnamed:@ "Save3viewcontroller"
Owner:self Options:nil];
Summarize:
Just looking at their initialization, it may feel the same. But if, open to see the relationship between Xib, only to realize that their integration classes are different.
1. Initwithnibname to load the class of xib that we have defined for the View Controller class
2. Different loading modes
Initwithnibname method: Is deferred loading, the control on this view is nil, only to need to display, will not nil
Loadnibnamed method: Instant loading, each element in the Xib object loaded with this method already exists.
(Carefully understand this rule: when using loadNibNamed:owner:options:, the File's owner should is NSObject, the main view should be your class Type, and all outlets should is hooked up to the view, not the File ' s Owner.)

The difference between the five, Initwithcoder and initWithFrame

Initwithoder is called when an object is loaded from the nib file, such as when your view is from the nib, then this function of the view is called. (called by the framework)
initWithFrame (is called by the user to initialize the object)

The Init method that gets used depends on how the view is created. It can be explicitly created using initwithframe or it can be created by loading a nib. In this case, the Initwithcoder method gets called when the view was loaded from the nib. There is other Init methods for subclasses (like Uitableviewcontroller had Initwithstyle), so you had to be sure which O NE is being called.

Self.showviewcontroller = [nib Lastobject];
[NIB objectatindex:0];

Excerpt from: Baidu with you in the team Baidu answer

Ios_init Related Information

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.