Instancetype instancetype on the type representation, as with the ID, you can indicate that any object type Instancetype can only be used on the return value type, and cannot be used as an ID on the parameter type · One benefit of instancetype than ID: The compiler detects the true type of instancetype. xib file Use xib file can be used to describe a piece of local UI interface xib File loading O Method 1
Nsarray *OBJS = [[NSBundle mainbundle] loadnibnamed:@ "Jhappview" Owner:nil Options:nil];
This method creates all the objects in the Xib and places the objects in the OBJS array in order
(If Xib is shown, then there are 3 objects in the OBJS array: 1 UIView, 1 UIButton, 1 uiswitch)
Ø Method 2
The bundle parameter can be nil, the default is the main bundle
uinib *nib = [uinib nibwithnibname:@ "Jhappview" Bundle:[nsbundle Mainbundle]];
Nsarray *OBJS = [nib Instantiatewithowner:nil options:nil];
• In the development phase, the Xib file is for developers; When the application is loaded on the phone, the Xib file will be converted to nib file • To adjust the size of the view in Xib, first set size to freeform, xib, and storyboard contrast • Common: Ø are used to describe the software interface Ø are used interface Builder tool to edit • Different points øxib is lightweight, used to describe the local UI interface Østoryboard is heavyweight, used to describe the entire software interface, and can show a jump relationship between multiple interfaces Iv. view encapsulation • If a view inside the child control is more, it is generally considered to customize a view, the creation of its internal sub-control screen up, do not let the outside concern • The outside world can pass the corresponding model data to View,view to get the model data to the internal child control set corresponding data
• To encapsulate a custom view using Xib
1> Create a custom view that inherits UIView, assuming the class name is called (Jhappview)
2> Create a new Mjappview.xib file to describe the structure inside the Jhappview
3> Modifying the type of UIView is Jhappview true Type
4> the inner child control with the Jhappview property connection
5> Jhappview provides a model property
6> overrides the set method of the Model property, because the model data passed in the set method can be obtained
7> The model data, setting the data to the corresponding sub-controls separately
8> Add: Provides a class method to create a jhappview that masks the code that reads the Xib file.
• To use code a custom view step
One more step than the above is to rewrite
-(ID) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self) {
Add sub-spaces and some one-time settings from space in this area
}
return self;
}
Use of instancetype,xib files