TableView lazy Jump way, load data source way

Source: Internet
Author: User

Almost, take the data source, say, n sections, each section inside the cell number is not fixed, the data source content is not necessarily, resulting in the cell form will be different

Fetch from the data source if you write if else, or switch is not satisfied, perhaps Swift is more bull, not mentioning

It's just that you want to calculate the index value of a unique data source array corresponding to a different cell based on the resource you have

Write bad, if there is better hope to share a bit, learn from each other! (Dozens of scetion should not be surprised by apparent efficiency)

Not much to say on the code:

-(Nsarray *) arraytitle

{

if (!_arraytitle) {

_arraytitle = @[@ "Don't let him (her) See my family tree", @ "Don't let him (her) see my News", @ "Don't look at his (her) dynamic"];

}

Return @[@ "Don't let him (her) See my family tree", @ "Don't let him (her) see my News", @ "Don't look at his (her) dynamic"];

}

-(Nsarray *) arrayvcforjump

{

if (!_arrayvcforjump) {

_arrayvcforjump = @[[mhnotshowfamilytreecontroller Class],[mhnotshoweventtoothercontroller class],[ Mhnotseeothereventcontroller class]];

}

return _arrayvcforjump = @[[mhnotshowfamilytreecontroller Class],[mhnotshoweventtoothercontroller class],[ Mhnotseeothereventcontroller class]];

}

#pragma mark calculates the index value of the current array, which is guaranteed not to repeat because of the Indexpath

-(Nsinteger) Getcurrentindexfordataarray: (nsindexpath*) Indexpath TableView: (UITableView *) TableView

{

//****************

self.numofindexpromate = 0;

for (Nsinteger i=0; i<indexpath.section; i++) {

Self.numofindexpromate + = [TableView numberofrowsinsection:i];

}

//***************

return self.numofindexpromate;

}

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath

{

Cell rarely temporarily does not consider reuse

Mhprivacytableviewcell * cell = [[Mhprivacytableviewcell alloc]init];

Cell.textLabel.textColor = Mheventcelltitlecolor;

Cell.textLabel.text = self.arraytitle[indexpath.row+indexpath.section];//The value here is not unique in more than one section and should be noted later

Nsinteger num = [self getcurrentindexfordataarray:indexpath tableview:tableview];

Cell.textLabel.text = Self.arraytitle[num+indexpath.row];

return cell;

}

#pragma mark-click the cell jump Agent

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath

{

Nsinteger num = [self getcurrentindexfordataarray:indexpath tableview:tableview];

Class strvcname = Self.arrayvcforjump[indexpath.row+num];

Class strvcname = self.arrayvcforjump[indexpath.row+indexpath.section];

NSString * strClassName = Nsstringfromclass (strvcname);

if ([strClassName iscontainonestr:@ "Controller"]) {

Uiviewcontroller * VC = [[Strvcname alloc]init];

[Self.navigationcontroller PUSHVIEWCONTROLLER:VC Animated:yes];

}

Else

{

Return

}

}

TableView lazy Jump way, load data source way

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.