ios - Hiding Tableview section headers on the fly -



ios - Hiding Tableview section headers on the fly -

i trying hide , display section headers when there or isn't info populating tableview. code have works intended occasionally, mostly, 1 or both of section headers remain displayed, (however, if drag header off screen when there no info disappear intended).

this code using hide/unhide sections.

-(uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { //create custom header titles desired header spacing if (section == 0) { uiview *headerview; if (self.searchusers.count || self.searchtracks.count) { headerview = [[uiview alloc]initwithframe:cgrectmake(0, 0, 320, 40)]; } else{ headerview = [[uiview alloc]initwithframe:cgrectmake(0, 0, 0, 0)]; } headertitlelabel *headertitle = [[headertitlelabel alloc] initwithframe:cgrectmake(17, 10, 150, 20) headertext:@"users"]; [headerview addsubview:headertitle]; homecoming headerview; } else if (section == 1){ uiview *headerview; if (self.searchusers.count || self.searchtracks.count) { headerview = [[uiview alloc]initwithframe:cgrectmake(0, 0, 320, 40)]; } else{ headerview = [[uiview alloc]initwithframe:cgrectmake(0, 0, 0, 0)]; } headertitlelabel *headertitle = [[headertitlelabel alloc] initwithframe:cgrectmake(17, 0, 150, 20) headertext:@"songs"]; [headerview addsubview:headertitle]; homecoming headerview; } else homecoming nil; } -(cgfloat)tableview:(uitableview *)tableview heightforheaderinsection:(nsinteger)section { //custom header spacing if (section == 0) { if (self.searchusers.count || self.searchtracks.count) { homecoming 40; } else homecoming 0; } else if (section == 1) { if (self.searchusers.count || self.searchtracks.count) { homecoming 50; } else homecoming 0; } else homecoming 0; }

i check if array has objects, if not set frame's height 0. doesn't seem working though. ideas how should go doing this? give thanks you.

your model should drive table view. don't homecoming 'number of rows' value model, 'number of sections' value.

consider array contains 2 arrays model.

ios objective-c uitableview

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -