Cancels the sticky effect of headers and footer in TableView
When I recently made a project, I encountered a bug, or limited personal ability, and thought for a long time didn't think the best way to go to reality.
So what's the problem?
First, when I set a header and a footer in Tabelview for the Not hungry section, when I slide the tableview, I find that the header and footer do not scroll with the cells in the TableView. And will live at the top of the bottom for a period of time, this effect, although good, but the above is not required by the function, so have to find a way to solve their own.
I remember sometimes the header does not stop, but why this time the header and footer are hidden?
Later found that the original set Tableview.tableheaderview = or Footerview time will not pause, it is of course, because this is part of the TableView, not part of the section.
I found a code like this on the Internet.
1 //Remove UITableView headerview stickiness (sticky)2 3- (void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {4 5 if(ScrollView = =Self.tableview)6 7 {8 9CGFloat sectionheaderheight = -;//SectionheaderheightTen One if(Scrollview.contentoffset.y <= sectionheaderheight && scrollview.contentoffset.y >=0) { A -Scrollview.contentinset = Uiedgeinsetsmake (-scrollview.contentoffset.y,0,0,0); - the}Else if(Scrollview.contentoffset.y >=sectionheaderheight) { - -Scrollview.contentinset = Uiedgeinsetsmake (-sectionheaderheight,0,0,0); - + } - + } A at}
But his function set Headerview can not set Footerview, oneself also try to supplement Footerview implementation, but found that the technology is limited, so, you understand!
Finally saw a foreign great God wrote a article to find the following code
1-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {2 3 if(ScrollView = =Self.tableview)4 5 {6 7UITableView *tableview = (UITableView *) ScrollView;8 9CGFloat sectionheaderheight = -;Ten OneCGFloat sectionfooterheight = -; A -CGFloat OffsetY =Tableview.contentoffset.y; - the if(OffsetY >=0&& OffsetY <=sectionheaderheight) - - { - +Tableview.contentinset = Uiedgeinsetsmake (-offsety,0,-sectionfooterheight,0); - +}Else if(OffsetY >= sectionheaderheight && OffsetY <= tableview.contentsize.height-tableview.frame.size.height -sectionfooterheight) A at { - -Tableview.contentinset = Uiedgeinsetsmake (-sectionheaderheight,0,-sectionfooterheight,0); - -}Else if(OffsetY >= tableview.contentsize.height-tableview.frame.size.height-sectionfooterheight && OffsetY < = Tableview.contentSize.height-tableview.frame.size.height) { - inTableview.contentinset = Uiedgeinsetsmake (-offsety,0,-(Tableview.contentsize.height-tableview.frame.size.height-sectionfooterheight),0); - to } + - } the *}
Note: Sectionheaderheight and sectionfooterheight are set according to the project.
Found basically done, and finally only need to set the corresponding padding can!
iOS Development--project summary & Cancel the sticky effect of header and footer in TableView