I have UITableView for display for chat message list. I am using 5 type of different with dynamic height. Minimum cell height from 20 to maxHeight( approx 1000 px). UITable view cell dynamic height is set by "self.messageTableView.rowHeight = UITableViewAutomaticDimension".
What Should be common estimate row height.
After reload UITableView content size not getting properly. If user scroll then content size increased.
It is not enough to just set rowHeight to automatic dimension. You also need to install proper constraints for cell subviews so the cell can calculate its height based on that constraints.
To use UITableViewAutomaticDimension for dynamic height calculation, ensure
1 - Leading, Trailing, Top and Bottom constraints to cell are added correctly and not creating any conflicts
2 - Add cell.layoutIfNeeded() in cellForRowAt method of UITableViewDelegate
3 - You can give any height as estimatedRowHeight, 44 is the default value, but you can give 20(your minimum) as well.
Related
I am trying to use the self-resizing cell in one of my custom cell in UITableview. This is for the varying address field so as the address length increases the table cell should also increase with the UILabel.
I am using the following constraints:
The error in console is:
Moreover, the table view is not showing this cell because of this. I have given :
UITableViewAutomaticDimension
For both estimatedHeightForRow and heightForRow
UILabel number of lines as 0
What is the issue and why it is happening?
To calculate the height of UITableViewCell, vertical constraints top and bottom of the corresponding subviews which you are considering relevant for height calculation must be connected to the other subviews in such a way that it eventually connects top and bottom constraint to the superview ie UITableViewCell.
Add top and bottom constraints to Main office label and other subviews also.
I was trying to explore the new feature of dynamic cell height using auto layout, introduced in Xcode 7 using this link. I have one UITableViewCell like this below
I want cell to adjust its size automatically based on the content in textView and size of image. I set all constraint and given estimatedRowHeight and UITableViewAutomaticDimension as tableview row height. But when i run the app i'm not able to see the UITextView below. Which means that cell height is not getting adjusted dynamically. Do i need to set the cell height programmatically or still i can do it using Auto Layout.
For TextView, it must not be scrollable.
Also, Your constraints are should be provided in such a way that, TableViewCell should get height automatically(there must be vertical spacing constraints between each component, Height of the each component must be there(it may be explicit of implicit height, but it must need to have height)).
Also, estimatedHeight you are providing must be near to actual average height.
If your tableViewCell is getting above things, then and then only it will get dynamic height based on its content.
I understand how to create custom UITableViewCells with a dynamic height in iOS8+.
Within our app we have some full size height cells, for error/loading states. Then we have some dynamic height cells for the actual correct content.
What is the correct way to handle a full height cell using the dynamic height approach? Previously we would use the heightForRowAtIndex and set the height to the be the tableView.frame.size.height for example.
Now we need to have some cells which would be fullsize, some which might be 200 and some which might be 240 as an example.
Just setup the constraints in your full size cells to calculate to the correct height. You can either give them a constant height constraint or base it on it's content.
That way you don't have to mix absolute and dynamic heights.
I'm trying to figure out how to limit a UICollectionView to display a horizontal scrollable list in a single row.
Any Ideas?
I just used something that is working for me:
Set the Scroll direction to Horizontal.
Set the size of your Cells using sizeForItemAt indexPath method.
Set a constraint to your CollectionView making its height equal to (or a bit greater than) the Cell's height which you specified above.
The logic behind it:
When the height of CollectionView is equal to the height of it's items and it is set to horizontal scroll, then it can only show them in one row. I said "or a bit greater than cell's height" because if you set the height of your CollectionView twice bigger than cell's height then it can fit 2 rows of cells and it will show them in 2 rows instead of one.
I have a custom UITableViewCell subclass, and say there is a UIPickerView inside of it. As far as I know the cell requires constraints on both its top and its bottom so that the height can be calculated. The problem is when I specify only the top and bottom constraints, the height of the cell displayed is like 44. So I added a height constraint for the UIPickerView to be 162, then the console says all these constraints cannot be satisfied simultaneously.
So how can I let the estimated height to be 162 so that the UIPickerView is displayed properly (Without overriding the height function of UITableViewDelegate?)