Click here to Skip to main content
15,665,942 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a tableview that display users chatting messages from server.
the tableview has a custom cell with one textview.
i want to adjust the textView width according to the message width(content width) that has been loaded from server.

using the mentioned code below , i could get the right width of each message when the view appear, however when i scroll up or down , a different width is assigned to the textview and my tableview get messed up.

What I have tried:

 let contentSize = cell.messageTextView.sizeThatFits(cell.messageTextView.bounds.size)
var frame = cell.messageTextView.frame
frame.size.height = contentSize.height
frame.size.width = contentSize.width
cell.messageTextView.frame = frame
cell.messageTextView.frame.size.height = contentSize.height
cell.messageTextView.frame.size.width = contentSize.width
Updated 28-Mar-18 4:23am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900