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:

  1. table view empty, press add button
  2. detail editor opens, edit data labels
  3. go uitableview
  4. -> draws -> no problem.
  5. redraws new data when editing corresponding content.

b. problem

  1. table view empty, press add button
  2. detail editor opens, edit data first 3 labels, not bottom 2 labels
  3. go uitableview
  4. -> draws edited labels, adjusts layout bottom horizontal stack view takes no space
  5. go detail editor again same cell, add text bottom 2 labels
  6. go table view controller
  7. -> problem: bottom line still not drawn
  8. 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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -