Last section we talked about how to show friends
IOS TableView Implementation QQ Friends List (ii)
http://blog.csdn.net/lwjok2007/article/details/46549111
Next we'll fold the grouped clicks.
Start by creating a new Mutable dictionary to store the current list for display
Nsmutablearray *selectedarr;//Control List is open
Selectedarr=[[nsmutablearray Alloc]init];
According to the first two sections, we say that the group name is placed on the header of section, but the header does not have the same click method as the cell.
At this point we can consider adding a button to the header to make the list open and close the list when clicked
-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) section{UIView *view=[[uiview Alloc]initwithframe:cgrectmake (0, 0, Screen_width,)]; View.backgroundcolor=[uicolor Whitecolor]; UILabel *titlelabel=[[uilabel Alloc]initwithframe:cgrectmake (5, Screen_width,)]; Titlelabel.text=[titlearray Objectatindex:section]; [View Addsubview:titlelabel]; Uiimageview *imageview=[[uiimageview Alloc]initwithframe:cgrectmake (5, 5, a)]; imageview.tag=20000+section; Imageview.image=[uiimage imagenamed:@ "Arrow_down.png"]; [View Addsubview:imageview]; Add a button to listen for click Grouping, to implement grouping expansion close. UIButton *btn=[uibutton Buttonwithtype:uibuttontypecustom]; Btn.frame=cgrectmake (0, 0, Screen_width,); btn.tag=10000+section; [Btn addtarget:self Action: @selector (btnopenlist:) Forcontrolevents:uicontroleventtouchdown]; return view;}
The tag for the button is 10000+section here to ensure that the button's tag identifies which group is currently clicked (not directly set to section but set to 10000+section is to ensure that the left side of the picture can also be determined by the tag which group, so his tag is set to 20000+section so that the section does not exceed 10000 when the two can be determined through the tag, and does not affect each other)
How to implement the button you just added
-(void) Btnopenlist: (UIButton *) sender{ nsstring *string = [NSString stringwithformat:@ "%d", sender.tag-10000]; The data stored in the array Selectedarr and the header want to correspond, convenient to do comparison if ([Selectedarr containsobject:string]) { [Selectedarr Removeobject:string]; } else { [Selectedarr addobject:string]; } [Tableviewlist Reloaddata];}
The top method is to follow a new Selectedarr array after clicking on the group,
Down we're going to implement table and new when reading Selectedarr decide whether to expand the grouping
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{NSString * INDEXSTR = [NSString stringwithformat:@ "%d", indexpath.section]; NSString *str=[titlearray ObjectAtIndex:indexPath.section]; Nsarray *arr=[datadic OBJECTFORKEY:STR]; static NSString *cellidentifier = @ "Usercell"; Usertableviewcell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; Cell=nil; if (cell = = nil) {cell = [[Usertableviewcell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:celli Dentifier]; Cell.selectionstyle = Uitableviewcellselectionstylegray; }//Only need to add user information to the section of the current group expansion if ([Selectedarr containsobject:indexstr]) {nsdictionary *dic=[arr objec TAtIndex:indexPath.row]; Cell.headerphoto.image=[uiimage imagenamed:[dic valueforkey:@ "Usericon"]; Cell.namelabel.text=[dic valueforkey:@ "name"]; [email protected] "[Online]"; [EMAIL&NBsp;protected] "no dynamics"; [email protected] "4G"; } return cell; }
Expand close at this point but the left side of the head has not yet been changed (the cutting head is down when it is expanded, and it is a super-cut when closed)
At this point we need to adjust the method
-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) section{UIView *view=[[uiview alloc ]initwithframe:cgrectmake (0, 0, Screen_width, 30)]; View.backgroundcolor=[uicolor Whitecolor]; UILabel *titlelabel=[[uilabel Alloc]initwithframe:cgrectmake (5, Screen_width, 30)]; Titlelabel.text=[titlearray Objectatindex:section]; [View Addsubview:titlelabel]; Uiimageview *imageview=[[uiimageview Alloc]initwithframe:cgrectmake (5, 5, 20, 20)]; Imageview.tag=20000+section; More current whether to expand the settings picture nsstring *string = [NSString stringwithformat:@ "%d", section]; if ([Selectedarr containsobject:string]) {imageview.image=[uiimage imagenamed:@ "arrow_down.png"]; }else{imageview.image=[uiimage imagenamed:@ "Arrow_right.png"]; } [view Addsubview:imageview]; Add a button to listen for click Grouping, to implement grouping expansion close. UIButton *btn=[uibutton Buttonwithtype:uibuttontypecustom]; Btn.frame=cgrectmake (0, 0, Screen_width, 50); btn.tag=10000+section; [Btn addtarget:self Action: @selector (btnopenlist:) Forcontrolevents:uicontroleventtouchdown]; [View ADDSUBVIEW:BTN]; return view;}
The final effect is as follows
This is basically the simple function of imitating the QQ friends list.
The source code will be uploaded to QQ group space
Apple Development Group: 414319235 Welcome to join the Welcome discussion question
IOS TableView Implementation QQ Friends List (three)