ios - how to set tableview accordion in swift? -


i new ios , trying design accordion menu.i got stucked..first made ui having static contents (labels in 3 rows in table view , views..).while trying set accordion..didnt show response..

here viewcontroller.swift

 func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {     let previndexpath = selectedindexpath     if indexpath == selectedindexpath     {         selectedindexpath = nil     }    else     {         selectedindexpath = indexpath     }      var indexpaths:array <nsindexpath> = []     if let previous = previndexpath     {         indexpaths += [previous]     }     if let current = selectedindexpath     {         indexpaths += [current]     }     if indexpaths.count > 0     {         tableview.reloadrowsatindexpaths(indexpaths, withrowanimation:uitableviewrowanimation.automatic)     }  }   func tableview(tableview: uitableview, willdisplaycell cell: uitableviewcell, forrowatindexpath indexpath: nsindexpath) {      (cell as! tableviewcell).watchframechanges()     (cell as! tableviewcell2).watchframechanges() }   func tableview(tableview: uitableview, didenddisplayingcell cell: uitableviewcell, forrowatindexpath indexpath: nsindexpath)  {     (cell as!tableviewcell).ignoreframechanges()     (cell as!tableviewcell2).ignoreframechanges() } override func viewwilldisappear(animated: bool) {     super.viewwilldisappear(animated)     cell in tblvw.visiblecells as! [tableviewcell] {         cell.ignoreframechanges()     }    cell in tblvw.visiblecells as! [tableviewcell2] {             cell.ignoreframechanges()     } }  func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat {     if indexpath == selectedindexpath {         return tableviewcell.expandedheight      } else {        return tableviewcell.defaultheight   }       if indexpath == selectedindexpath {         return tableviewcell2.expandedheight    } else {        return tableviewcell2.defaultheight     }    return 0.0  } 

i have same problem. problem when implement multiple cells. solution is:

override func viewwilldisappear(animated: bool) {     super.viewwilldisappear(animated)       cell in tableview.visiblecells {          if(cell.reuseidentifier == "your_identifier_from_cell")         {             let ncelda = cell as! tableviewcell             ncelda.ignoreframechanges()         }          else         {             let mcelda = cell as! tableviewcell2             mcelda.ignoreframechanges()         }     } } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -