ios - How to change height of custom cell on button's click? -


i have issue regarding height of custom cell. need increase height of cell when 1 button on cell clicked. know use 2 methods (heightforrow , didselectrow) confuse when clicked on button time custom method button action called , using 2 methods in controller.i attached code:

in customcell.m

- (ibaction)btnrestplusclicked:(id)sender {     uibutton *btn = (id)sender;     btn.selected =!btn.selected;     if (btn.selected)     {          nslog(@"selected");        // _viewextrascheduleamount.hidden = false;//i need make event on button action , same time increase height of cell.     }     else     {         btn.tag = 0;        // _viewextrascheduleamount.hidden = true;     } 

now need when button clicked time row's height increase.

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {      //if (ceel.btnrestplusclicked.selected)      //{     //    return 100;    // }    // return 60;  know wrong here how use method?  } 

please can 1 me out this? thanks

create nsmutabledictionary inside of uiviewcontroller store nsindexpath of btnrestplusclicked cells.

then track when button plus selected in each cell:

in customcell.h

@protocol customcelldelegate;  @interface customcell : uitableviewcell     @property (nonatomic, weak) id<customcelldelegate> delegate; @end  @protocol customcelldelegate <nsobject> - (void)customcellbuttonplusselected:(customcell*)cell; @end 

in customcell.m

- (ibaction)btnrestplusclicked:(id)sender {     [self.delegate customcellbuttonplusselected:self]; } 

in uiviewcontroller when create cell cellforrowatindexpath add:

cell.delegate = self 

and conform uiviewcontroller customcelldelegate

-(void)customcellbuttonplusselected:(customcell*)cell {     nsindexpath *indexpath = [self.tableview indexpathforcell:cell];     nsstring *key = [nsstring stringwithformat:@"%li:%li", indexpath.section, indexpath.row];     [buttonplusclickeddictionary setobject:@"1" forkey:key];     [self.tableview reloadrowsatindexpaths:@[indexpath]]; }  - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     nsstring *key = [nsstring stringwithformat:@"%li:%li", indexpath.section, indexpath.row];     if ([buttonplusclickeddictionary objectforkey:key]) {         return 100;     }      return 60;  } 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -