#pragma mark -#pragma mark Table view data source//tableView How many of them are there? section- (Nsinteger) Numberofsectionsintableview: (uitableview *) tableview { // return the number of sections. return [ Mutablearrayorder count];} Each section has several lines (several elements)- (Nsinteger) TableView: (uitableview *) tableview Numberofrowsinsection: (Nsinteger) Section { // return the number of rows in the section. return 1;} #pragma mark - tableView headView//tableView section head View Height-( CGFloat) TableView: (uitableview *) Tableview heightforheaderinsection: (Nsinteger) section{ return 40.0;} tableview section Head View-(uiview *) TableView: (uitableview *) tableview ViewforhEaderinsection: (Nsinteger) section{ uiview *headview = [[uiview Alloc] initwithframe:cgrectmake (0, 0, self.view.frame.size.width, 40)]; &NBSP;HEADVIEW.BACKGROUNDCOLOR&NBSP;=&NBSP;[UICOLOR&NBSP;COLORWITHRED:1&NBSP;GREEN:1&NBSP;BLUE:1&NBSP;ALPHA:1] ; uiimage *image = [uiimage imagenamed:@ " Shop. png "]; uiimageview *businesslogo = [[uiimageview alloc] Initwithframe:cgrectmake (10, 12, 15, 15)]; [businesslogo setimage: image]; uilabel *titlelabel = [[uilabel Alloc] initwithframe:cgrectmake (40, 0, 150, 40)]; Titlelabel.backgroundcolor = [uicolor clearcolor]; titlelabel.textcolor = [UIColor darkGrayColor]; titleLabel.font = [UIFont systemFontOfSize:13]; uiimage *imagearrow = [uiimage imagenamed:@ "Right _02.png"]; uiimageview *arrowview = [[uiimageview alloc] initwithframe: CGRectMake (200, 12, 15, 15)]; [arrowview setimage:imagearrow]; uilabel *ordertaglabel = [[uilabel alloc] initwithframe:cgrectmake (headview.frame.size.width-60, 0, 150, 40)]; orderTagLabel.backgroundColor = [UIColor clearColor]; Ordertaglabel.textcolor = [uicolor darkgraycolor]; ordertaglabel.font = [uifont systemfontofsize:13]; if ([ mutablearrayorder count] >0) {&NBSP;&NBSP;&NBSp; orderentity *entity = [mutablearrayorder objectatindex: section]; titlelabel.text = entity.store_name; orderTagLabel.text = entity.status; } [headView addSubview:businessLogo]; [headview addsubview:titlelabel]; [headview addsubview:arrowview] ; [headview addsubview:ordertaglabel]; return headview;} #pragma mark - tableView footView//tableView section trailer View Height-( CGFloat) TableView: (uitableview *) Tableview heightforfooterinsection: (Nsinteger) section{ return 90.0;} tableview section 's Tail View-(uiview *) TableView: (uitableview *) Tableview viewforfooterinsection: (Nsinteger) section{ uiview * Footview = [[uiview alloc] initwithframe:cgrectmake (0, 0, 320, 90)]; footview.backgroundcolor = [uicolor colorwithred:1 green:1 blue:1 alpha:1];//[uicolor blackcolor]; uilabel * Titlelabel = [[uilabel alloc] initwithframe:cgrectmake (0, 0, self.view.frame.size.width-10, 39)]; titlelabel.backgroundcolor = [ Uicolor clearcolor]; titlelabel.textcolor = [uicolor darkgraycolor] ; titlelabel.font = [uifont systemfontofsize:13]; titleLabel.textAlignment = NSTextAlignmentRight; uilabel *linelabel = [[uilabel&nbSp;alloc] initwithframe:cgrectmake (0, 40, self.view.frame.size.width, 1)]; linelabel.backgroundcolor = [uicolor colorwithred:0.95 green:0.93 blue:0. 92 alpha:1]; uibutton *delorder = [[ Uibutton alloc] initwithframe:cgrectmake (SELF.VIEW.FRAME.SIZE.WIDTH-270,&NBSP;45,&NBSP;80,&NBSP;30)] ; [delorder.layer setcornerradius:5.0]; //Set Rectangle four fillet radius [ delorder.layer setborderwidth:1.0]; //Border Width cgcolorspaceref colorspace = cgcolorspacecreatedevicergb (); cgcolorref colorref = Cgcolorcreate (ColorSpace, (cgfloat[]) { 0.9, 0.9, 0.9, 1 }); [ delorder.layer setbordercolor:colorref];//Border Color [delorder settitle: @ " Delete Order " forstate: uicontrolstatenormal]; delorder.titlelabel.font = [uifont systemfontofsize: 14.0];// [delorder setbackgroundcolor: [uicolor bluecolor]]; [delOrder setTitleColor:[UIColor blackColor]forState:UIControlStateNormal]; UIButton *getLogistics =[[UIButton alloc] Initwithframe:cgrectmake (self.view.frame.size.width-180, 45, 80, 30)]; [ getlogistics.layer setcornerradius:5.0]; //Set Rectangle four fillet radius [getlogistics.layer setborderwidth:1.0]; //Border Width [getlogistics.layer setbordercolor:colorref ];//border Color [getlogistics settitle: @ "Delete order" forState: uicontrolstatenormal]; getlogistics.titlelabel.font = [uifont Systemfontofsize: 14.0];// &nbsP [Getlogistics setbackgroundcolor: [uicolor bluecolor]]; [getlogistics setTitleColor:[UIColor blackColor]forState:UIControlStateNormal]; uibutton *ordercomment =[[uibutton alloc] initwithframe:cgrectmake ( SELF.VIEW.FRAME.SIZE.WIDTH-90,&NBSP;45,&NBSP;80,&NBSP;30)]; [ordercomment.layer setcornerradius:5.0]; //Set Rectangle four fillet radius [orderComment.layer setBorderWidth:1.0]; //Border Width [ordercomment.layer setbordercolor:colorref];//border color [ordercomment settitle: @ "to pay" forState: UIControlStateNormal]; orderComment.titleLabel.font = [UIFont systemFontOfSize: 14.0];// [ordercomment setbackgroundcolor: [uicolor bluecolor]]; [ Ordercomment settitlecolor:[uicoLor blackcolor]forstate:uicontrolstatenormal]; uilabel *linelabel2 = [[uilabel alloc] initwithframe:cgrectmake (0, 80, SELF.VIEW.FRAME.SIZE.WIDTH,&NBSP;1)]; linelabel2.backgroundcolor = [uicolor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1]; uilabel *linelabel3 = [[uilabel alloc] initwithframe:cgrectmake (0, 81,&NBSP;SELF.VIEW.FRAME.SIZE.WIDTH,&NBSP;10)]; linelabel3.backgroundcolor = [uicolor colorwithred:0.95 green:0.93 blue:0.92 alpha:1]; if ([mutablearrayorder count] >0) { OrderEntity *entity = [mutableArrayOrder objectAtIndex:section]; titlelabel.text = [nsstring stringwithformat:@ "%@%@%@%@%@", @ "Total: ¥ ", entity.total_amount,@ " (including freight: ¥ ", entity.ship_cost,@") "]; } [footview addsubview:titlelabel]; [footview addsubview:linelabel];// [footview addsubview:delorder]; [footview addsubview: getlogistics]; [footview addsubview:ordercomment]; [ footview addsubview:linelabel2]; [footview addsubview:linelabel3]; return footview;} Elements in tableview cell - (uitableviewcell *) TableView: (uitableview *) TableView cellforrowatindexpath: (nsindexpath *) indexpath {// Identifier Find cell View static nsstring *[email protected] "Ordertableviewcell"; ordertableviewcell *cell = (OrderTableViewCell *) [tableview dequeuereusablecellwithidentifier:coupontableviewcellidentifier]; //prevent No cell lead to bug error run failure, make code more robust, safe, stable, effective if (Cell == nil) { nsarray *array = [[nsbundle mainbundle] loadnibnamed:@ "Ordertableviewcell" owner:self options:nil]; cell = [array objectAtIndex:0]; } cell.selectionStyle = Uitableviewcellselectionstylenone; if ([mutableArrayOrder count] > 0) { orderentity *entity = [Mutablearrayorder objectatindex:indexPath.row]; for (int i = 0; i < [entity.product_list count]; i++) { orderproductentity *productentity = [entity.product_list objectAtIndex:i]; cell.productName.text = productEntity.product_name; [cell.productImage sd_setBackgroundImageWithURL:[NSURL urlwithstring:productentity.album_thumb] forstate:uicontrolstatenormal]; cell.introduce.text = productEntity.introduce; cell.goodsCnt.text = [NSString stringwithformat:@ "%@%@", @ "x ",productentity.count]; cell.price.text = productentity.price; } } return cell;} #pragma mark return each group header title name-(nsstring *) TableView: (uitableview *) tableview Titleforheaderinsection: (Nsinteger) section{ return @ "Head";} #pragma mark return description of each set of tails-(nsstring *) TableView: (uitableview *) tableview Titleforfooterinsection: (Nsinteger) section{ return @ "tail";} Set the height of each line element- (cgfloat) TableView: (uitableview *) Tableview heightforrowatindexpath: ( nsindexpath *) indexpath { return 100;} #pragma mark -#pragma mark Table view delegate//tableVIew Click events for each line element - (void) TableView: (uitableview *) Tableview didselectrowAtindexpath: (nsindexpath *) indexpath { }
Ps:
The following three functions must be implemented in Viewcontroller
(1) Numberofsectionsintableview:
How many sections are there in a table?
(2) Tableview:numberofrowsinsecion:
How many units or rows each section needs to load
(3) Tableview:cellforrowatindexpath:
UITableViewCell instances, used to form the table view
Tableviewcontroller use, TableView some common methods