uitableview - Label and frame expansion on button click in iOS -


i need expand frame , label on click of button in section of table view. similarly, when button clicked again, frame , label should restore original (compressed) state. has done sections of table view. if click on button of 1 section, it's expanding frames sections. label expanded on clicked section. below code:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {                        nsuinteger section = [indexpath section];      if(section==0 || section==2)     {                            static nsstring *myidentifier = @"tablecell";          dugsprojecttablecell *cell = (dugsprojecttablecell*)[tableview dequeuereusablecellwithidentifier:myidentifier];         cell.readmorebutton.tag=[indexpath section];          [cell.readmorebutton addtarget:self action:@selector(buttonpressed:) forcontrolevents:uicontroleventtouchupinside];          if (section==0) {              cell.mylabel.text=@"on festive season 1 of leading real estate developers in ncr delhi, launching new residential project ";         }          else if (section==2){             cell.mylabel.text=@"situated in hot & fast upcoming neighbourhood,spread in 30 acres,located in heart of city";         }          if(self.isheightchanged)         {                                    if ([cell.readmorebutton.titlelabel.text isequaltostring:@"read more"]) {                  [cell.readmorebutton settitle:@"read less" forstate:uicontrolstatenormal];                  cell.readmorebutton.frame=cgrectmake(223, 90 , 66, 25) ;                  cgrect frame = cell.mylabel.frame;                  cell.mylabel.numberoflines=0;                 cell.mylabel.linebreakmode=nslinebreakbywordwrapping;                 frame.size.height=100;                 cell.mylabel.frame=frame;              }              else if ([cell.readmorebutton.titlelabel.text isequaltostring:@"read less"])             {                 [cell.readmorebutton settitle:@"read more" forstate:uicontrolstatenormal];                  cell.readmorebutton.frame=cgrectmake(223, 70 , 66, 25) ;                  cgrect frame = cell.mylabel.frame;                  cell.mylabel.numberoflines=0;                 cell.mylabel.linebreakmode=nslinebreakbywordwrapping;                  frame.size.height=30;                 cell.mylabel.frame=frame;              }         }         return  cell;     }      else if (section==1){          static nsstring *myidentifier = @"unitcell";          dugsunitplancell *cell = (dugsunitplancell*)[tableview dequeuereusablecellwithidentifier:myidentifier];          return cell;      }      return null; } 

below code button click:

 (void)buttonpressed:(uibutton *)button {     dugsprojecttablecell *selectedcell = (dugsprojecttablecell*)[[button superview] superview];     if (selectedcell) {            if ([button.titlelabel.text isequaltostring:@"read more"] ) {             whichbutton=@"m";             nslog(@"%@",whichbutton);         }          else if ([button.titlelabel.text isequaltostring:@"read less"]){            whichbutton=@"l";             nslog(@"%@",whichbutton);          }         nslog(@"%d",selectedcell.readmorebutton.tag);          nsindexpath *indexpath = [nsindexpath indexpathforrow:0 insection:selectedcell.readmorebutton.tag];         selectedindexpath=indexpath;         nslog(@"%@",selectedindexpath);         self.isheightchanged=yes;         [self.tableviewforpropertyoverview reloadrowsatindexpaths:@[selectedindexpath ] withrowanimation:uitableviewrowanimationautomatic];      }  } 

below code expanding frame:

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     if([indexpath section]==1){         return 60;     }      if (([indexpath section]==0)||([indexpath section]==2)) {          if (selectedindexpath!=null){             return 120.0f;          }          else{             return 60.0f;      }}  } 

the frame size increased 120 sections. instead, should section 0 & 2 when buttons inside them clicked. please advise.

i think don't have 3 sections rather 1 section 3 table view cells.

it seems there misconception sections , rows. write:

i need expand frame , label on click of button in section of table view.

this not make sense. there no ui elements in table view section. rather, section contains rows (cells) in turn contain labels, etc. , might display section header. want expand rows belonging section.

your heightforrowatindexpath cannot return else 60.0 if second section. mind you, method not return "section height" height of row. if 3 spaces see expanded, must in section 0.

assuming need 1 row per section need to:

  • return 3 in numberofsections
  • return 1 in numberofrowsinsection

finally, check button's text determine 1 not practice. can tag button integer , check [(uibutton*)sender tag] in handler. see using tag somewhere there, not clear why need string constant well.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -