ios - After using self sizing cells reloadData doesn't work anymore -


i have uitableview custom cell. there button, 1 label , 1 hidden label in cell. want hidden label visible after clicking button. when using self sizing cells can't reload tableview after setting hidden label visible.

the self sizing cells working fine these 2 lines of code in viewdidload() function.

self.tableview.estimatedrowheight = 68.0 self.tableview.rowheight = uitableviewautomaticdimension 

this viewcontroller class:

class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate {  @iboutlet weak var tableview: uitableview! override func viewdidload() {     super.viewdidload()      //self sizing cells     self.tableview.estimatedrowheight = 68.0     self.tableview.rowheight = uitableviewautomaticdimension }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return 1 }  func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     var cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! customcell     cell.leftlabel.text = "left label"     cell.centerlabel.text = "i center label , need little more words because supposed wrap content. hope enough"     cell.button.tag = indexpath.row     cell.button.addtarget(self, action: "buttonaction:", forcontrolevents: uicontrolevents.touchupinside)     return cell }  func buttonaction(sender: anyobject) {     var button: uibutton = sender as! uibutton     let indexpath: nsindexpath = nsindexpath(forrow: button.tag, insection: 0)     var cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! customcell     cell.centerlabel.hidden = false     self.tableview.reloaddata() } } 

as call

self.tableview.estimatedrowheight = 68.0 

the reloaddata call in buttonaction function doesn't work anymore.

can me out problem? thanks!

try this. use cellforrowatindexpath grab cell @ position in tableview, not dequeuereusablecellwithidentifier

func buttonaction(sender: uibutton) {     var indexpath:nsindexpath = nsindexpath(forrow:sender.tag, insection: 0)     var cell = tableview.cellforrowatindexpath(indexpath) as! customcell     cell.centerlabel.hidden = false } 

then if want hide centerlabel when cells reused, add method in customcell class

override func prepareforreuse() {     self.centerlabel.hidden = true } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -