ios - (Swift) Expand and Collapse tableview cell when tapped -


good morning

i created custom tableviewcell, internally has collectionviewcell , directional arrow. able make cell expand , collapse when expand 1 cell , click on 1 previous collapse. example: if cell expanded , cell tapped, want cell contract , cell expand @ same time. 1 cell can in expanded state in given moment changing targeting arrow.

example:

if cella expanded , cellb tapped, want cella contract , cellb expand @ same time. 1 cell can in expanded state in given moment changing targetting arrow.

my code:

func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath) {           switch(selectedindexpath)     {      case nil:          let cell = mytableview.cellforrow(at: indexpath) as! tableviewcell         cell.arrowimagem.image = uiimage(named:"content_arrow2")         selectedindexpath = indexpath        default:         if selectedindexpath! == indexpath         {              let cell = mytableview.cellforrow(at: indexpath) as! tableviewcell             cell.arrowimagem.image = uiimage(named:"content_arrow")             //cell.reloadinputviews()             selectedindexpath = nil          }       }      self.mytableview.beginupdates()      self.mytableview.reloaddata()       //mytableview.reloadrows(at: [indexpath], with: .automatic)      self.mytableview.endupdates()  }   func tableview(_ tableview: uitableview, heightforrowat indexpath: indexpath) -> cgfloat {          let index = indexpath      if selectedindexpath != nil{         if(index == selectedindexpath)         {             return 147         }         else{             return 67         }     }     else     {         return 67     }    } 

you can need coding. first of detect when row selected (keep index path of selected row in variable). when row selected add index path of new selected row , of selected (that have in variable) in array pass tableview reloadrows inside didselectrowat, function force redrawing of 2 rows , heightforrowat function called height of both rows, in heightforrowat check selected row (do remember variable mentioned earlier?) , return expanded height that, while others return collapsed height. should result want. hope help.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -