(1) Effect
(2) Source code in the material download
Http://pan.baidu.com/s/1jfdr4
(3) Summary
--the attribute with marked state should be in the corresponding model class, and the Getter method should be renamed to Isxxx;
--uitableviewheaderfooterview can not be used with xib and can only be created with code.
The--layoutsubviews method is to automatically invoke this method when changing the height of the parent control, so the frame of the child control is usually set here. Because the child controls change with the parent control. Note here that the parent control in the initialization method does not have a frame, so the child control setting frame is not used.
-(void) layoutsubviews{ [Super layoutsubviews]; The Y values of frame and bounds are different here, because our X and Y are always 0, so we use bounds self.btn.frame=self.bounds; CGFloat labely=0; CGFloat labelw=150; CGFloat labelh=self.frame.size.height; CGFloat Labelx=self.frame.size.width-15-labelw; Self.labelonbtn.frame=cgrectmake (LabelX, labely, Labelw, LABELH);}
--didmovetosuperview is called when a child control is loaded onto the parent control. If we need to refresh the TableView data, then we can set the state of the child control elsewhere is not valid, because it will be refreshed and changed to the original appearance. Therefore, you should set the state of the child control in this method, and so on (equivalent to intercepting the child control to load the parent control on the process, and then make some settings, etc.).
-(void) didmovetosuperview{ if (self.fGroup.isClick) { self.btn.imageview.transform= Cgaffinetransformmakerotation (m_pi_2); } else if (!self.fgroup.isclick) { self.btn.imageview.transform=cgaffinetransformmakerotation (0); }
--model initialization, the first use of setvaluesforkeyswithdictionary to inject all the attributes, and then for the individual special processing, the last cover can be.
-(Instancetype) Initwithdict: (nsdictionary *) dict{ if (self=[super init]) { //turn all properties into [self ] SETVALUESFORKEYSWITHDICTIONARY:DICT]; Then deal with the special properties, the dictionary array into an array of objects Nsmutablearray *newfriendarray=[[nsmutablearray alloc]init]; For (Nsdictionary *dict in self.friends) { wpfriend *singlefriend=[wpfriend friendwithdict:dict]; [Newfriendarray addobject:singlefriend]; } Self.friends=newfriendarray; } return self;}
--Set the height of the TableView per group of heads
self.tableview.sectionheaderheight=40;
-This is the content that sets the header for each group of TableView, similar to setting the cell content. This is relative to titleforheader ... A bit richer, because it can be a uiview, and the pair should be returned with an object of the Uitableviewheaderfooterview class.
-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (Nsinteger) section{}
--expand and close the list of friends, in fact, according to determine the state after the click, return 0 rows or the original number of rows.
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{wpfriendgroup * Groups=self.friendgroup[section]; return groups.isclick?0:groups.friends.count;}
In this case, the main difficulty is to set the header content of each group, and to set some state properties to record and judge the small operations.
"iOS Development-67" QQ Friends List case: Uitableviewheaderfooterview class, Layoutsubviews and Didmovetosuperview method, etc.