Implementing multiple cell Layouts for Tabelview

Source: Internet
Author: User

-(void) viewdidload {

[Super viewdidload];

Self.Labelarray=[[nsmutablearray alloc]< Span class= "S6" >initwithobjects:@ " personal data ,@ " My favorites " ,@ " my message " ,@ " My listings ",@" My footsteps " , @ " feedback " ,@ " About "nil

self. Picarray=[[nsmutablearray alloc]initwithobjects:@ "C11",@ "C12", @ "C13",@ "C14",@ "C15",@ "C16",@ "C17",Nil];

additional setup after loading the view, typically from a nib.

}

number of rows displayed

-(Nsinteger) TableView: (uitableview *) TableView numberofrowsinsection: (nsinteger) section{

return self. Picarray.count;

switch (section) {

case 0:

return 1;

break;

case 1:

return 4;

break;

default:

return 1;

break;

}

}

Number of sections

-(Nsinteger) Numberofsectionsintableview: (uitableview *) tableview{

return 3;

}

reuse mechanism, reuse cell

-(uitableviewcell *) TableView: (uitableview *) TableView Cellforrowatindexpath: ( Nsindexpath *) indexpath{

Tttableviewcell *cell=[tableview dequeuereusablecellwithidentifier:@ "Celltest" Forindexpath: Indexpath];

Switch (indexpath. Section) {

case 0:

Cell. imageviewt. Image=[UIImage imagenamed:self. Picarray[0]];

Cell. labelviewt. Text=self. Labelarray[0];

break;

case 1:

Cell. imageviewt. Image=[UIImage imagenamed:self. Picarray[Indexpath. Row+1]];

Cell. labelviewt. Text=self. Labelarray[Indexpath. Row+1];

break;

case 2:

Cell. imageviewt. Image=[UIImage imagenamed:self. Picarray[Indexpath. Row+5]];

Cell. labelviewt. Text=self. Labelarray[Indexpath. Row+5];

break;

default:

break;

}

return cell;

}

Click to jump

-(void) TableView: (uitableview *) TableView Didselectrowatindexpath: (nsindexpath *) indexpath{

if(Indexpath. Section= =0) {

[self performseguewithidentifier:@ "1" sender: indexpath];

}Else if(Indexpath. Section= =1) {

Switch (indexpath. Row) {

case 0:

[self performseguewithidentifier:@ "2" sender: indexpath];

break;

case 1:

[self performseguewithidentifier:@ "3" sender: indexpath];

break;

default:

break;

}

}Else

[self performseguewithidentifier:@ "7" sender: indexpath];

}

Cell Overhead Distance

-(cgfloat) TableView: (uitableview *) TableView heightforheaderinsection: (nsinteger) Section {

return ;

}

TableView the last color

-(UIView *) TableView: (UITableView *) TableView viewforfooterinsection: (Nsinteger) section{

UIView *view=[[uitableview Alloc]init];

UIView *view=[[uitableview alloc]initwithframe:cgrectmake (0, 0, 20, 100)];

View.backgroundcolor=[uicolor Lightgraycolor];

return view;

//}

-(cgfloat) TableView: (uitableview *) TableView heightforfooterinsection: (nsinteger) section{

return ;

}

PS: Custom cell to create a uitableviewcell for it, you can drag directly to the current controller in the cell to implement the method

Implementing multiple cell Layouts for Tabelview

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.