objective c - UITableView expandable/collapsable sections in iOS 8,Particular row section is not expandable/collapsable -
after lots of googling uitableview expandable/collapsable sections still didn't correct answer , have tried still got nothing.

when clicked first section of reminder,it hides this.

so here question make right. i'm working on application need expand collapse rows in different sections. tried expanding collapsing rows single section. want same happen in multiple sections.can tell me wrong have done , suggest me.
bool expand,collapsed; - (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { //headerview myview = [[uiview alloc] initwithframe:cgrectmake(0.0, 0.0, 300.0, 80.0)]; // add label uilabel *headerlabel = [[uilabel alloc] initwithframe:cgrectmake(ksectiontitleleftmargin, ksectiontitletopmargin,tableview.bounds.size.width - ksectiontitleleftmargin - ksectiontitlerightmargin,30.0 - ksectiontitletopmargin - ksectiontitlebottommargin)]; // whatever headerlabel configuration want here headerlabel.text = [self tableview:tableview titleforheaderinsection:section]; [myview addsubview:headerlabel]; uitapgesturerecognizer *headertapped = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(sectionheadertapped:)]; [myview addgesturerecognizer:headertapped]; //up or down arrow depending on bool uiimageview *updownarrow = [[uiimageview alloc] initwithimage:expand ? [uiimage imagenamed:@"uparrowblack"] : [uiimage imagenamed:@"downarrowblack"]]; updownarrow.autoresizingmask = uiviewautoresizingflexiblerightmargin; updownarrow.frame = cgrectmake(265.0, 2.5, 25.0, 25.0); [myview addsubview:updownarrow]; return myview; } #pragma mark - gesture tapped - (void)sectionheadertapped:(uitapgesturerecognizer *)gesturerecognizer { nsindexpath *indexpath = [nsindexpath indexpathforrow:0 insection:gesturerecognizer.view.tag]; { collapsed = !collapsed; // reload specific section animated nsrange range = nsmakerange(indexpath.section, 1); nsindexset *sectiontoreload = [nsindexset indexsetwithindexesinrange:range]; [self.tableview reloadsections:sectiontoreload withrowanimation:uitableviewrowanimationfade]; [self.tableview reloaddata]; } } - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { if (reminders.count!=0) { return 2; } else { return 1; } } -(cgfloat)tableview:(uitableview *)tableview heightforheaderinsection:(nsinteger)section { return 30; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { if ((reminders.count!=0) && (section==0)) { return reminders.count; } else { return 15; } }
here sample collapsable tableview.
method tab gesture -(void)sectionbuttontouchupinside:(uitapgesturerecognizer*) gesturerecognizer{ [self.tableview beginupdates]; uiview *sender = [gesturerecognizer view]; int section = sender.tag; bool shouldcollapse = ![_collapsedsections containsobject:@(section)]; if (shouldcollapse) { nsarray* indexpaths = [self indexpathsforsection:section withnumberofrows:[[_arritems objectatindex:section] count]]; [self.tableview deleterowsatindexpaths:indexpaths withrowanimation:uitableviewrowanimationtop]; [_collapsedsections addobject:@(section)]; } else { nsarray* indexpaths = [self indexpathsforsection:section withnumberofrows:[[_arritems objectatindex:section] count]]; [self.tableview insertrowsatindexpaths:indexpaths withrowanimation:uitableviewrowanimationtop]; [_collapsedsections removeobject:@(section)]; } [self.tableview endupdates]; } -(nsarray*) indexpathsforsection:(int)section withnumberofrows:(int)numberofrows { nsmutablearray* indexpaths = [nsmutablearray new]; (int = 0; < numberofrows; i++) { nsindexpath* indexpath = [nsindexpath indexpathforrow:i insection:section]; [indexpaths addobject:indexpath]; } return indexpaths; }
Comments
Post a Comment