Note When using IOS xib

Source: Internet
Author: User

The usual steps to use for 1.xib

1.1 Create a new 1 class to describe this xib (assuming that it inherits from UIView and the class name is Diyview)

1.2 New 1 Xib, file name is also Diyview, drag a uiview inside, set the UIView property-class for Diyview

1.3 Drag 1 long press gesture recognition to xib, right mouse button just dragged in uiview,gesture recognizer and just dragged in the long press gesture recognition to do the connection

1.4 DIYView.h provides a method class method: + (instancetype) Diyview;

DIYVIEW.M Implementation Diyview:

+ (Instancetype) Diyview

{

return [[[NSBundle Mainbundle] loadnibnamed:@ "Diyview" Owner:nil Options:nil] lastobject];

}

1.5 in the controller, add the view defined by the Xib

Diyview *diy = [Diyview Diyview];

[Self.view Addsubview:diy];

1.6 Last Run program, program crashes

1.7 Analysis of the cause of the error:

[Diyview Diyview] Returns a gesture, not an expected uiview. Because the last addition is a long-press gesture.

1.8 Summary:

When using Xib, pay attention to what lastobject or Firstobject returns.

1.9 Circumvention Methods

You can print an array to see the order of the elements in the array

Nsarray *array = [[NSBundle mainbundle] loadnibnamed:@ "Diyview" Owner:nil Options:nil]

NSLog (@ "%@", array);

Note When using IOS xib

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.