0
votes

I am working on a UITableView which has 2 sections, both of which have exactly 1 row which is a custom cell. This custom cell has a collection view which is used to display various products.

Specific to my issue, the two collection views have 6 cells(three rows in the collection view). However when I load the page, the second section only displays 4 cells (two rows in the collection view). I am using UITableViewAutomaticDimension for the tableview which has the cells that contain these collection views.

I have tried using setLayoutNeeded and layoutIfNeeded, I am calling reload data on the tableView in a number of places. I am reloading the second section specifically as well. However the only way the cell's dimensions get fixed is if I scroll down to the second section, then scroll up to the first and then go back to the second.

I have been stuck on this for the past 3 days and absolutely any help would be greatly appreciated.

1
Are your table rows fixed size? You need to set estimatedRowHeight too - tbilopavlovic
I have set it to 1000 after I set the delegate and datasource of the tableview which is double of what I actually need it to be. - Sagar Daundkar
You should detect the problem more accurately. Maybe the problem is with second section's UITableViewCell height? Or your collection view (that is a subview inside UITableViewCell) is smaller size that it needs to be? Or maybe there's something wrong with collection view layout properties at the moment of displaying it's content? You can detect this by inspecting your view hierarchy in "View debugger" or coloring collection view and cell's background in different colors. Also please check your console, collectionview may print warnings if it can't calculate it's layout (something's wrong) - Alexander Tkachenko
If your rows are of fixed size, then don't use UITableViewAutomaticDimension but implement delegate method of UITableViewDelegate - heightforrowatindexpath - tbilopavlovic

1 Answers

0
votes

However the only way the cell's dimensions get fixed is if I scroll down to the second section, then scroll up to the first and then go back to the second.

According to this, I think you should reload your collection views firstly. And then reload your table view.