ios - Smooth UITableView Cell Expansion With Accordion Style -


my table view can expand , collapse cells when pressed, content appears when cell expands loads before animation finished.

what left this:

uitableview accordion expansion

what this example. content appears if behind curtain , cell expansion animation reveals it.

here code controls table view:

class historyviewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate{      var expandedindexpath: nsindexpath? // index path of cell expanded     let collapsedheight: cgfloat = 44.0 // constant set default collapsed height     var tickethistoryservice = tickethistoryservice() // service gather info ticket history coredata      var tickets = [ticket]()      @iboutlet var tableview: uitableview!      override func viewdidload() {         super.viewdidload()          // remove appended table view cells         tableview.tablefooterview = uiview()          self.tickets = self.tickethistoryservice.fetchdata() // load inital data      }      // mark: - table view methods      func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         return self.tickets.count     }      func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {          let cell = self.tableview.dequeuereusablecellwithidentifier("cell") as! historytableviewcell          let ticket = self.tickets[indexpath.row]          cell.titlelabel!.text = ticket.ticketnumber         return cell     }      func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {         if editingstyle == .delete {             self.tickethistoryservice.removeobject(indexpath.row)             self.tickets = self.tickethistoryservice.fetchdata()             tableview.deleterowsatindexpaths([indexpath], withrowanimation: .fade)         }     }      func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {         self.tableview.beginupdates()         let cell = self.tableview.cellforrowatindexpath(indexpath) as! historytableviewcell         if indexpath.isequal(self.expandedindexpath){ // if selected cell selected             self.expandedindexpath = nil             cell.commentlabel.hidden = true         }         else {             self.expandedindexpath = indexpath             cell.commentlabel.hidden = false         }         self.tableview.endupdates()     }      func tableview(tableview: uitableview, willdeselectrowatindexpath indexpath: nsindexpath) -> nsindexpath? {         let cell = self.tableview.cellforrowatindexpath(indexpath) as! historytableviewcell         cell.commentlabel.hidden = true         return indexpath     }      func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat {         if indexpath.isequal(self.expandedindexpath) {             return uitableviewautomaticdimension         }         return collapsedheight     } } 

one approach have cell clip subview content expand outside of itself:

let cell = self.tableview.dequeuereusablecellwithidentifier("cell") as! historytableviewcell cell.clipstobounds = true 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -