Issues with dynamic height for UITableViewCell with UIStackView while scrolling up - ios

I have a table view with cells with dynamic heights. Inside each cell, I have an image view and a group of 4 labels in a vertical stack view. When I first load the tableview, the cells look fine and the height is calculated correctly. This is also true for the cells that load after scrolling downwards. However, as soon as I scroll up, the height of the cell becomes huge (bigger than the entire screen).
Im not sure why this happens only when I scroll up.
tableview after initial loading
tableview after scrolling upwards

I set the spacing parameter for UIStackView to a value not 0 and it worked!

Related

Increase the collectionView height constraint dynamically for the horizontal scrolling collectionView

I have added horizontal scrolling collection View in a scrollView and set the height as 10. I tried to change the height of the collection view dynamically using the above code it worked but cells are adding in multiple lines I mean just like grid view but I need horizontal scrolling and should not view like grid view instead it should view as the number of items in a single row just like below image
self.hei_col_offers.constant = self.col_offers.contentSize.height
self.view.layoutIfNeeded()

Horizontal and Vertical Scrolling Usign UICollectionView and ScrollView

I have an app in which There is a Card View.
I have put the card in UICollectionViewCell.
My Flow layout is Horizontal.
Cards was scrolling Horizontaly.
Now the problem rises when I have to support iPhone4s.
The Vertical Length of Card is Very long to fit in Screen.So I have to Scroll the Content in UICollectionView Vertically also.
So I Decided to put my UICollectionView inside UIScrollView.
In my viewDidLoad I am setting the content size of UIScrollView.
But it is not scrolling.
What I am missing.??
you can have tableview and then add collection view in tableview cell and thus you can have horizontal as well as vertical scrolling without any interruption.
UITableView->UITableViewCell->UICollectionView in tableview cell->load cells in collectionview

Force UICollectionView to scroll until a specific cell is centered

First of all, I already read How to force UICollectionView with fewer items to scroll? and it did not solve my problem.
I have an horizontal UICollectionView with 5 cells, and only 5 cells are needed to fill the screen width. This means the 3rd cell is centered. How can I scroll so the 4th cell is centered?
When using scrollToItemAtIndexPath, it won't scroll since there is not enough cells to scroll. In other words, if I want my 4th cell to be centered, there would be a blank space at the end since I only have 5 cells (and vice-versa for the 2nd cell).
Is adding empty cells the only solution?
You could adjust the insets on the collection view. Add enough space that you can center the last cell.
More info from Apple

On Dynamically increasing height of one collectionview cell gap is seen in other cell

On Dynamically increasing height of one collectionview cell gap is seen in other cell. How to get rid of the unwanted gap.
Please help
1. Collection view before expanding cell
2. Collection view after dynamically expanding height of the cell on button click -- GAP seen

UICollectionView cells, auto layout and collectionview layout changes

I have a collection view which displays cells looking like a classic table view with image, title and subtitle.
I want to be able to switch the layout to a grid showing only the images, 3 in a row.
The content of the collection view cell is layouted in a storyboard with auto layout. The imageView has the following constraints:
Leading 0 to the left cell edge
Top 0 to the top cell edge
Bottom 0 to the bottom cell edge
Fixed width
Horizontal space to the labels
After the layout change the imageView should have constraints of zero to all edges of the container, so that it fills it completely.
At the moment when I change the layout the app crashes with Unable to simultaneously satisfy constraints.. What is the best way to fix the constraints when the layout is changed, maybe even replace the cell class?
Turns out the problem was in some other part of the code.
You can change the collectionView layout with setCollectionViewLayout:animated:completion: and reload the visible cells in the completion block.

Resources