Then IOS uses the nib file (a) to come.
There's a way in testnibview.m.
-(ID) Initwithcoder: (nscoder *) Adecoder;
This method comes from the Nscoding protocol. Nscoding protocol as below, there are two methods.
@protocol nscoding-(void) Encodewithcoder: (Nscoder *) acoder;-(ID) Initwithcoder: (Nscoder *) Adecoder; Ns_designated_initializer@end
These two methods are required for nib files to be able to save and restore objects. These two methods are also implemented when we need to archive our own custom objects. Both methods have been implemented for UIView (including subclasses) and Uiviewcontroller (including subclasses) systems. When instantiating an object using the Xib file, first
-(nsarray *) loadnibnamed: (nsstring *) name owner: (ID) owner options: (nsdictionary *) options;
is called, then the system invokes Initwithcoder to instantiate the object that implements the Nscoding protocol, and the Init method is invoked without an object that implements the Nscoding protocol. As described in the documentation, Initwithcoder is only part of the Loadnibnamed method.
In iOS using the nib file (a), say one of the methods in Testnibview
+ (instancetype) Testnibview { return [[[NSBundle mainbundle]loadnibnamed:@ ' Testnibview ' owner:self options: NIL] firstobject]; }
This view, which uses a separate xib file, can only be used by code, and there is no way to use it in other xib. Suppose in a.xib, we drag a uiview called view, set its class to Testnibview, this time, and Testnibview class associated xib is not testnibview.xib, but the view, We can add a button to the view that can be associated as a button for outlet and Testnibview.
It is important to note that the Initwithcoder method is just an Init method, it just ensures that init, as for outlet these associations in this method does not complete the relationship, this step, the print Self.button is nil. Loadnibnamed also calls awakefromnib after Initwithcoder. And in the Awakefromnib method, these outlets, delegate to ensure that all associations, this method [super awakefromnib] After printing Self.button is not empty. In general, we don't need to do anything in awakefromnib, except for things that can't be set up in Xib, Reload remembers calling [Super Awakefromnib].
Copyright Notice: Welcome to comment and reprint, but please keep the source!
IOS using the nib file (ii)