ios - UILabel does not wrap on initial load within TableViewCell -


i creating chat based app, uses uitableview hold messages within conversation. create chat bubble, have wrapper view (wrapview) constrained top, bottom, right, , left of tableviewcell. subview have uilabel holds message sent. used preferredmaxlayoutwidth uilabel ensure text within label won't go beyond parent view. number of lines uilabel set 0. set following parameters within cellforrowatindexpath function:

// cell let cell = tableview.dequeuereusablecellwithidentifier("leftbubbletext") as! lefttexttableviewcell  // set message cell.messagelabel.text = message  // set message label's max width cell.messagelabel.preferredmaxlayoutwidth = cell.wrapview.frame.width - 16 

when conversation first loads, text within uilabel not wrapped properly. truncated @ end of wrapper view. when cell scrolled off screen , re-appears, text wrapped fine after cell reused.

how can ensure text within uilabel wrapped on initial load , not when cell reused?

the issue frame width using wrong. cells created using deqeuereusablecellwithidentifier have no size class associated them because have no parent view. hence if have constraints in cell, trying calculate layout sizes manually not work properly.

you should using dequeuereusablecellwithidentifier:forindexpath dequeue cells


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -