UITabIeView CustomCell is not working properly before scrolling... in swift - ios

I am trying to design a comments Controller but unfortunately i am doing something wrong . I used uiTableview for this purpose.
On run time my customcell with more comment text is hiding behind the customcell with less amount of data.
This is the layout structure
As shown above customcell has a uiimageview and a stackview. Stackview has to uilabels. I also setted stackview distribution to proportionally.
Although when i scroll everything becomes fine.
I also used this in on ViewDidLoad
tableView.rowHeight = UITableView.automaticDimension

Looks like a constrains issue still few steps you can do
Set constrains properly, Number of lines = 0 to label
Make sure of below code you use in viewdidload
tableView.estimatedRowHeight = YourTableViewHeight
tableView.rowHeight = UITableViewAutomaticDimension

Related

UITableViewCell is not expanding to fit height of UILabel, what am I doing wrong?

What I want is my UITableViewCell to expand/shrink based on the height of the UILabel inside.
I have tried just about every solution I could find and it's not working. Maybe I have some setting that's preventing it.
Here is a screenshot of the UITableViewCell settings:
For the UILabel inside, Lines is set to 0 and Line Break to Word Wrap.
In the UIViewController where I'm showing the table view, I am setting this in viewDidLoad():
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 44
tableView.reloadData()
And in cellForRowAt after dequeuing the cell I'm doing (instructionText being the UILabel):
cell.instructionText.numberOfLines = 0
I've seen this in many tutorials and it works, why not for these cells? The content comes out like this:
This is driving me crazy! Thanks for any help!
EDIT: Here are the UILabel settings:
Please check your label constraints

Unable to display UILabel in multiple lines in tableView

I have a tableView cell with two labels as shown below. The constraints for these labels can be seen in the images.
For each label, I have set the number of lines to 0 and the line break option to Word Wrap. However, when the tableView loads, the texts get shown in a single line as below.
What might be causing this issue?
It might have happened because it takes the custom height of the UITableViewCell
Please set estimatedRowHeight and rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableViewAutomaticDimension
It will solve your problem
Thank you!!!

how do I make tableviewcell height to autogrow

I have a tableviewcell with two labels and the label's height will change depending on the content so tableviewcell height will automatically change.
now how can I make tableview cell height to autogrow ?
Please clarify me if the tableview cell height will autogrow if the label height changes ?
To make it tableview cell autogrow you have to keep in mind of the following two things in mind,
Right constraint(top, bottom, right & left) for the UI elements inside the tableview cell.
Usage of UITableViewAutomaticDimension & estimatedRowHeight property as follows,
tableView.estimatedRowHeight = 100 // A rough estimated height for your cell.
tableView.rowHeight = UITableViewAutomaticDimension
Refer the following tutorial for better indepth explanation on how to implement it.
http://matteomanferdini.com/the-correct-way-to-display-lists-in-ios-and-what-many-developers-do-wrong/#autolayout
https://www.youtube.com/watch?v=e1KJQs0frbM

Auto layout cell based on subview or custom cell height

In the image. Comments has a textview that has text overflown to below 3 cells . Ideally that should not happen.
I have a tableview with custom cells as xib files and some custom cells are subviews. Please let me know how to add auto layout for this subviews or xib's.
I read many posts they suggested.below code. But it doesn't work.
In ViewDidLoad.
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 50;
Please suggest a solution. Thank you.
It will works, but you need to update the height everytime a new character is input, so in your cellForRow, add textview.delegate = self, and in the textViewDidChange, do tableView.beginUpdate() and tableView.endUpdate(), the cell height will update correctly

how to set tablecell row height automatically based on inner view outlet?

I want to set tableview cell height automatically to show the label completely without happening like that?
Any help?
There are 2 things that you need to do:
1st thing: Set AutoLayout for it.
2nd thing: implement these code:
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 100
You can see more from my project: https://github.com/khuong291/Yelp

Resources