Iosbug Log-Tableviewcell multiplexing

Source: Internet
Author: User

Three methods are listed below.

New cell file

including. H. M. xib

Then add a label to the Xib file with the purpose of reusing the cell

First, initialize a class method in the Listcell to be called

+ (Listcell *) Cellwithtableview: (UITableView *) Tablaeview;

+ (Listcell *) Cellwithtableview: (UITableView *) Tablaeview

//{

static NSString *identifier = @ "Listcell";

Listcell *cell = [Tablaeview dequeuereusablecellwithidentifier:identifier];

if (!cell) {

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

//    }

//

return cell;

//

//}

Second, register the nib directly in the Tableviewcontroller

-(void) Viewdidload {

[Super Viewdidload];

[Self.tableview registernib:[uinib nibwithnibname:@ "Listcell" Bundle:[nsbundle Mainbundle]] ForCellReuseIdentifier: @ "Listcell"];

Uncomment the following line to preserve selection between presentations.

Self.clearsselectiononviewwillappear = NO;

Uncomment the following line to display a Edit button in the navigation bar for this view controller.

Self.navigationItem.rightBarButtonItem = Self.editbuttonitem;

}

Listcell *cell = [TableView dequeuereusablecellwithidentifier:@ "Listcell"];

Third, use Registerclass:[listcell class] but must initialize cell before use

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

{

if (self = [super Initwithstyle:style Reuseidentifier:reuseidentifier]) {

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

}

return self;

}

Three methods as a result

PS: Note that the Awakefromnib method will be used every time the cell is called

The output is as follows

Iosbug Log-Tableviewcell multiplexing

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.