ios - Expand custom section cells in UITableView -


1)here problem.i designing ios app need show contents of cell on clicking on section(my custom sections).i have 2 such sections.now logic used here i'm hiding cell until click on section.but problem i'm facing in regard when 1st cell expands,it overlaps second section fraction of second.the reason following code:

    //call uitableview delegate method 'cellforrowatindexpath:'     [tableview beginupdates];     //some code     [tableview endupdates]; 

now i'm calling 'cellforrowatindexpath:' unhide cell gets executed after updates.

2)second logic thought set height each row 0 @ start.but ain't helping designs of both custom cells overlap each other.

what should now?

use following code expandable cell uitableview

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"cell";        uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease];     }     cell.textlabel.text=[[self.arfortable objectatindex:indexpath.row] valueforkey:@"name"];     [cell setindentationlevel:[[[self.arfortable objectatindex:indexpath.row] valueforkey:@"level"] intvalue]];         return cell; } 

code expanding & collapsing rows – tableview didselectrow method

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     [tableview deselectrowatindexpath:indexpath animated:yes];     nsdictionary *d=[self.arfortable objectatindex:indexpath.row];     if([d valueforkey:@"objects"]) {         nsarray *ar=[d valueforkey:@"objects"];         bool isalreadyinserted=no;         for(nsdictionary *dinner in ar ){             nsinteger index=[self.arfortable indexofobjectidenticalto:dinner];             isalreadyinserted=(index>0 && index!=nsintegermax);             if(isalreadyinserted) break;          }         if(isalreadyinserted) {             [self minimizethisrows:ar];         } else {                     nsuinteger count=indexpath.row+1;             nsmutablearray *arcells=[nsmutablearray array];             for(nsdictionary *dinner in ar ) {                 [arcells addobject:[nsindexpath indexpathforrow:count insection:0]];                 [self.arfortable insertobject:dinner atindex:count++];             }             [tableview insertrowsatindexpaths:arcells withrowanimation:uitableviewrowanimationleft];         }     } } 

a method minimize & maximize/expand-collapse rows.

-(void)minimizethisrows:(nsarray*)ar{     for(nsdictionary *dinner in ar ) {         nsuinteger indextoremove=[self.arfortable indexofobjectidenticalto:dinner];                 nsarray *arinner=[dinner valueforkey:@"objects"];         if(arinner && [arinner count]>0){             [self minimizethisrows:arinner];         }         if([self.arfortable indexofobjectidenticalto:dinner]!=nsnotfound) {             [self.arfortable removeobjectidenticalto:dinner];             [self.tableview deleterowsatindexpaths:               [nsarray arraywithobject:[nsindexpath indexpathforrow:indextoremove insection:0]]                       withrowanimation:uitableviewrowanimationright];         }     } } 

download code here


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

Fatal error: Call to undefined function menu_execute_active_handler() in drupal 7.9 -

python - RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK -