Use of instancetype,xib files

Source: Internet
Author: User

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

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.