ios - Issue on TableView Cell -


here i'm developing expanded tableviewcell ,while tableview didselectrowatindexpath method using cell expand, here used 2 tableview cell's enter image description here

but need button action secondcell expanded.can please how can implement here below code,

 - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {         // disable touch on expanded cell     uitableviewcell *cell = [self.thetableview cellforrowatindexpath:indexpath];     if ([[cell reuseidentifier] isequaltostring:@"expandedcellidentifier"]) {         return;     }          // deselect row     [tableview deselectrowatindexpath:indexpath                              animated:no];          // actual index path     indexpath = [self actualindexpathfortappedindexpath:indexpath];          // save expanded cell delete later     nsindexpath *theexpandedindexpath = self.expandedindexpath;          // same row tapped twice - rid of expanded cell     if ([indexpath isequal:self.expandingindexpath]) {         self.expandingindexpath = nil;         self.expandedindexpath = nil;     }         // add expanded cell     else {         self.expandingindexpath = indexpath;         self.expandedindexpath = [nsindexpath indexpathforrow:[indexpath row] + 1                                                     insection:[indexpath section]];     }      [tableview beginupdates];      if (theexpandedindexpath) {         [_thetableview deleterowsatindexpaths:@[theexpandedindexpath]                              withrowanimation:uitableviewrowanimationnone];     }     if (self.expandedindexpath) {         [_thetableview insertrowsatindexpaths:@[self.expandedindexpath]                              withrowanimation:uitableviewrowanimationnone];     }      [tableview endupdates];          // scroll expanded cell     [self.thetableview scrolltorowatindexpath:indexpath                              atscrollposition:uitableviewscrollpositionmiddle                                      animated:yes]; } 

but want implement while button taps secondcell expanding.

- (ibaction)expand:(id)sender {  } 

can please me ,thank you.

this solution can achieve logic creating separate .xib file disabling size classes. use boolean variable check whether selected. if so, reload specific cell , use delegate method heightforrow , determine boolean variable here. simple... hope understood. if not, please let me know. i'll share code worked out.

edited post , below code :-

    @implementation viewcontroller     bool sel=no;     nsmutablearray *a,*b;     nsindexpath *path;     - (void)viewdidload {         [super viewdidload];         a=[[nsmutablearray alloc] initwithobjects:@"apple",@"mango",@"orange",@"pineapple",@"cricket",@"bike",@"music", nil];         b=[[nsmutablearray alloc] initwitharray:a copyitems:yes];             [self.tview registernib:[uinib nibwithnibname:@"cell1" bundle:nil] forcellreuseidentifier:@"cell"];         // additional setup after loading view, typically nib.     }      - (void)didreceivememorywarning {         [super didreceivememorywarning];         // dispose of resources can recreated.     }      -(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{          return a.count;     }       -(nsinteger)numberofsectionsintableview:(uitableview *)tableview{         return 1;     }       -(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{         [tableview beginupdates];         if([[a objectatindex:indexpath.row] isequaltostring:@"selected"]){             sel=no;         [a replaceobjectatindex:indexpath.row withobject:[b objectatindex:indexpath.row]];         }         else{         [a replaceobjectatindex:indexpath.row withobject:@"selected"];             sel=yes;         }          [tableview reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationnone];         [tableview endupdates];     }      -(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath{         if([[a objectatindex:indexpath.row] isequaltostring:@"selected"]){         return 100;     }         return 60;     }      -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{          static nsstring *cellidentifier = @"cell";         cell1 *cell = (cell1 *)[tableview dequeuereusablecellwithidentifier:cellidentifier];         // if there no cell reuse, create new 1         /*  if(cell == nil)          {          cell = [[listcustomcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];          }*/         if (!cell)         {             cell = [[cell1 alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];         }         nslog(@"%f",[self tableview:self.tview heightforrowatindexpath:indexpath]);         cell.btn.frame=cgrectmake(cell.btn.frame.origin.x, [self tableview:self.tview heightforrowatindexpath:indexpath]*0.3, cell.btn.frame.size.width*1.3, cell.btn.frame.size.height);         uibutton *b=[[uibutton alloc] initwithframe:cell.btn.frame];          [cell.btn removefromsuperview];         [b settitle:@"button" forstate:uicontrolstatenormal];         [cell.contentview addsubview:b];         [b addtarget:self action:@selector(checkbuttontapped:) forcontrolevents:uicontroleventtouchupinside];         return cell;     }      - (void)checkbuttontapped:(id)sender     {         cgpoint buttonposition = [sender convertpoint:cgpointzero toview:self.tview];         nsindexpath *indexpath = [self.tview indexpathforrowatpoint:buttonposition];         if (indexpath != nil)         { //just make sure you've selected no selection option tableview.             [self tableview:self.tview didselectrowatindexpath:indexpath];             nslog(@"you've selected row %ld",(long)indexpath.row);         }     }     @end 

create separate .xib , place button there. resizing button's frame, need remove , add again while refreshing. hope helps :)


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -