ios - Custom UITableViewCell is reloaded with new data but not drawn with new data -
i have custom uitableviewcell following structure
customcell content view vertical stack view title label horizontal stack view label label horizontal stack view label label
on tap there segue detail view controller. when coming back, reload tableview in main task.
i see following happen:
a. no problem:
- table view empty, press add button
- detail editor opens, edit data labels
- go uitableview
- -> draws -> no problem.
- redraws new data when editing corresponding content.
b. problem
- table view empty, press add button
- detail editor opens, edit data first 3 labels, not bottom 2 labels
- go uitableview
- -> draws edited labels, adjusts layout bottom horizontal stack view takes no space
- go detail editor again same cell, add text bottom 2 labels
- go table view controller
- -> problem: bottom line still not drawn
- but debugger shows cell rendered , data available , label texts set
i call reloaddata() in main thread. not doing cause of missing updates of uitableviewcells. not in case.
-> have workaround, see answer below. applying workaround solves problem.
edit asked:
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier(workoutcellidentifier2, forindexpath: indexpath) as! workouttableviewcell let workout = appdelegate.persistence.workouts[indexpath.row] cell.setworkout(workout, healthdata: appdelegate.healthdata) return cell }
it never goes fallback path
i appears layout process of cell optimizes away bottom line when contains empty labels (text == nil)
the first 2 lines more vertical space.
when label texts set later, layout process doesn't reverse. setneedslayout()
doesn't help. bottom line still optimized away though contains data when redrawing.
workaround:
never set label text nil in cell. set " " when no data available.
now the bottom line never optimized away. empty space remains indicates there not set yet.
Comments
Post a Comment