About Xib need to pay attention to the place

Source: Internet
Author: User

When you need to write a tedious interface but still a static page, you will probably use the Xib

"Exception: When creating a file that inherits from UIView, without the tick option to automatically generate XIB, developers need to manually new a xib file with the same name, selecting the appropriate file name in the class on the right side of the Xib file"

A few things to note:

(1) All controls in a xib can only be placed in their own @interface declaration, not in other files

(2) Learn to use the Init method properly, load xib, need to loadnibname, put in the Init method will be better, so that we can later add some other control settings in the Init method, when called in the controller only need to fill out the Init method , no need to worry that it is xib or pure code, use the following:

-(Instancetype) init{

self = [super init];

if (self) {

Here's the point:

self = [[[NSBundle mainbundle]loadnibnamed:@ "Jyemainactivitypageview" Owner:nil Options:nil] firstObject];

Some of the other settings can be written here

}

return self;

}

This is the case in the cell:

-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier{

self = [super Initwithstyle:style reuseidentifier:reuseidentifier];

if (self) {

self = [[[NSBundle mainbundle]loadnibnamed:@ "Jyeminecell" owner:self Options:nil] lastobject];

Some other settings "if the contents of the cell are from model, you can also define a model property and make some other settings in his set method"

}

return self;

}

(3) or this: sign up and let your tableview know which cells it's looking for in the reuse pool.

[Self.tableview registernib:[uinib Nibwithnibname:nsstringfromclass ([Jyerecordcell class]) Bundle:nil] Forcellreuseidentifier:nsstringfromclass ([Jyerecordcell class])];

Jyerecordcell * Recordcell = [TableView dequeuereusablecellwithidentifier:nsstringfromclass ([Jyerecordcell class])];

About Xib need to pay attention to the place

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.