ios - how to cell size increse or resize on the button click? -
i have custom table view contains 2 buttons dynamically in cell row index path ,
i want when click increase size should increased , button should hide , ,
then 1 button resize row height should visible - in advance .
-(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { return jcoutcellsize; } - (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]; } // ----------------------- cellbackground image----------------------------- cell.backgroundview =[[uiimageview alloc]initwithframe:cgrectmake(160, 151, 320, 108)]; cell.backgroundview = [[uiimageview alloc] initwithimage: [uiimage imagenamed:@"incellfullbg.png"]]; //*********** change cell background colour***** // cell.contentview.backgroundcolor = [uicolor darkgraycolor]; //----------------------------cell buttons------------------------------------------- if (jcoutcellsize==152) { uibutton *addcomment = [uibutton buttonwithtype:uibuttontypecustom]; // custom means transparent takes shape same backgroup image [addcomment addtarget:self action:@selector(testbtns:) forcontrolevents:uicontroleventtouchdown]; // [addcomment settitle:@"1" forstate:uicontrolstatenormal]; addcomment.frame = cgrectmake(9.0, 128.0, 96.0, 26.0); [cell.contentview addsubview:addcomment]; uiimage *buttonaddcomment = [uiimage imagenamed:@"addcomment.png"]; [addcomment setbackgroundimage:buttonaddcomment forstate:uicontrolstatenormal]; [cell.contentview addsubview:addcomment]; } if (jcoutcellsize==152) { nslog(@" arrow %f",jcoutcellsize); uibutton *uparrow = [uibutton buttonwithtype:uibuttontypecustom]; [uparrow addtarget:self action:@selector(resizecell:) forcontrolevents:uicontroleventtouchdown]; //[downarrow settitle:@"arrow" forstate:uicontrolstatenormal]; uparrow.frame = cgrectmake(143.0, 136.0, 26.0, 16.0); [cell.contentview addsubview:uparrow]; uiimage *buttonup = [uiimage imagenamed:@"uparrow.png"]; [uparrow setbackgroundimage:buttonup forstate:uicontrolstatenormal]; [cell.contentview addsubview:uparrow]; nslog(@" cell size = %f",jcoutcellsize); } //---------------------------------------------------------------------------------- if (jcoutcellsize==132) { nslog(@" down arrow %f",jcoutcellsize); uibutton *downarrow = [uibutton buttonwithtype:uibuttontypecustom]; [downarrow addtarget:self action:@selector(incresecellhight:) forcontrolevents:uicontroleventtouchdown]; //[downarrow settitle:@"arrow" forstate:uicontrolstatenormal]; downarrow.frame = cgrectmake(143.0, 116.0, 26.0, 16.0); [cell.contentview addsubview:downarrow]; uiimage *buttondown = [uiimage imagenamed:@"updownarrow.png"]; [downarrow setbackgroundimage:buttondown forstate:uicontrolstatenormal]; [cell.contentview addsubview:downarrow]; nslog(@" cell size = %f",jcoutcellsize); } return cell; }
in view didload have done jcoutcellsize=152;
to change row height button click, should following steps: 1. create flag indicate row expanded, example _expandedindexpath
implement correct datasource method that:
-(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath*)indexpath { if (_expandedindexpath isequal:indexpath) { return jcbigcellsize; // large cell } else return jcoutcellsize; // normal cell }
to define on cell button pressed, set tag of button corresponding indexpath.row (in tableview:cellforrowatindexpath:)
on button action (incresecellhight:) tag of button, set _expandedindexpath indexpath, want see expanded (most [nsindexpath indexpathforrow:sender.tag insection:0]) , reload corresponding row using uitableview's method reloadrowsatindexpaths:withrowanimation:
this call datasource methods row (tableview:heightforrowatindexpath: , tableview:cellforrowatindexpath:), , cell increase it's height animation, specified in withrowanimation: parameter.
Comments
Post a Comment