In my UITableViewCell, when I load data into it, I have 2 UILabels which can have an unlimited number of lines.
I handle both of them like this:
label.numberOfLines = 0
label.lineBreakMode = .ByWordWrapping
When I initially load data into the UITableView, for some reason sometimes the cells on the screen don't yet show the whole String in the labels. Instead they just don't enlarge themselves.
However, when I scroll down so that they're off the screen and then scroll back up, everything looks perfect.
Why is this? How do I fix this issue?
In my cellForRowAtIndexPath
I basically use dequeueReusableCellWithIdentifier(:forIndexPath:)
then, I do cell.configureViews(...)
and return.
In my PostCell I do the label editing above in the override func layoutSubviews()
You might have forgotten to set the 0 lines property on the storyboard too...
Go to your Storyboard, select the label, and click Attributes Inspector.
Under Label you should see "Lines 0" like in the screenshot below:
Also, make sure you are handling the excess of characters the way you want - below is an example of the settings to wrap the text to a new line:
You need to calculate your UILabel height and use it as cell height before the cell drawn.
Try this to calculate the UILabel height UILabel height calculation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.