Collectionview inside tableview cell with dynamic height cells and dynamic content swift 4 - ios

I am working with collectionview inside tableviewcell in Swift 4. I get the content from server which is all dynamic. I have to show different types of collectionview behaviours.
For example, in the first tableview row should be collectionviewcell with screenwidth and scrollable. In the second row, collectionview with 3 sections and each section has different content different number of items.
Here I got stuck I am unable to show 3 sections one below other it is showing besides horizontally. I have calculated collectionview flow layout size.
Also in last row I have collectonviewcell with scrollable content,here when i scoll the content is repeating from bottom row or top row. I want the smoth scrolling and to stop repeating the content.
I am new to Swift. Can anybody help me out of this . Thanks in advance.

The smooth way is to create tableview with its cell xib and inside its cell add collection view and create another xib for collection view cell. This method is helpful when accessing collection view for different tableview cell. Rather using without loading Xib's may mixup your code.
You have to set tableview cell height as UITableViewAutomaticDimension. This will handle your cell height as per your dynamic content.
For each tableview cell you have to set collection view's property by using cell's index path as per your requirement.

Related

how to load two different dynamic tableview cells in same UITableViewVibrantCell

I have been trying two add two dynamic cells to a UITableView based on server response which will be having two scenarios.If the trip has been cancelled then that perticularcell should load one cell.If the trip has been completed then that cell should load the second cell.Can any one help me to load these cells based on server status.Thankyou In advance.
you should use stack view vertical and dynamic tableview cell height.
it means in your stack view you have 2 or more views.
the tableview cell height is dynamic so when you hidden first view the second view showing and the stack view size fixed.
so use below code in viewDidLoad to set the height of table view automatically:
tableView.estimatedRowHeight = YourTableViewHeight
tableView.rowHeight = UITableViewAutomaticDimension
hope to helping you

UITableView inside UITableViewCell height not working as expected

I have a UITableView which have some cells that will be always be there, one cell with a UICollectionView in it that will act like tabs, and finally one cell with a UITableView in it, whose data will change.
Then when the user selects one of this "tabs", I want to reload the nested table to show the correct data rows (the height of this rows will be dynamic).
I have already achieved that the nested table changes on the collection item selection, but the problem I am facing is that the UITableView inside the cell is not sizing properly.
I have build a sample app just to simplify the views. As you can see in the screenshot, the cell that contains the table is not filling the rest of the screen, so the 10 rows are not visible unless you scroll this table.
What I want is this table to fill the rest of the screen. The user must be able to scroll the main tableview, not the nested one, and still see all of the nested table cells.
I can't do this with multiple sections because I will have a header section that will be always fixed on top, if I had another section, it's header will replace the sticky one on scroll.
I have set the rowHeight of the main UITableView to UITableViewAutomaticDimension and an estimatedRowHeight too. I have pinned it to top, left, right and bottom of the cell's ContentView.
Can you help me with this, please? If it helps, I could upload the sample project and link it here.
Thank you very much!
If you are using autolayout then,
Give height constant to nested table view, create outlet for that height constraint.
When you reload that nested table, you will get that table's content size.
Fetch height from that content size and modify height constraint.

How to scroll the UICollectionview from particular cell

I have a collection view. I need to scroll only cell4, cell5, cell 6 so on. First two cells are remain same. Is is possible using only UICollectionview. How to achieve this.
FYI: the height of the cell is more than the screen height.
One of options would be to subclass UICollectionViewLayout and update frames in attributes of first three cells every time when scroll offset changes. So the cells would look static.

How to get height of UITableView placed in another UITableView in Cell as childViewController

I'm struggling with wired kind of problem. I have UITableView with one cell. This cell is only holding containerView with childViewController (second tableView). My problem is that, first tableView(parent) must have UITableViewAutomaticDimension row height but it doesn't work (It dosen't know correct size of that cell with second tableView).
How to get correct size of second tableView) ?
Second tableView (inside Cell) have scrollingEnabled turned off (tableView.scrollEnabled = false), first tableView must have correct size of second tableView in order to provide correct scrolling experience.
Since a UITableView inherits from UIScrollView you can use the contentSize property to get this information. This is how the scrollbar works on the side.
I have done a similar thing before (long ago), so the following is somewhat hazy/ irrelevant/ unessecary. There might be some gotchas with unknown/unrendered cell heights in the embedded tableview. I rememeber having to set the tableview height to a large number (forcing all cells to render) fetching the contentSize then resetting the tableview height to the contentSize.height.
Are you shure you really need second table view? If you have just one cell probably you don't need it. I recommend you to calculate table view height as the summ of it's cells heights. If cells of embedded table view have constant height it could be simple. In other case you also could calculate cells height.

AutoLayout setup for a UITableView within a UITableViewCell

I want to show multiple labels in my main UITableViewCell, for which I am trying to use a UITableView within the cell. Now I have setup all the delegates and datasources properly, and the data is coming in right. But the inner UITableView has a dynamic number of cells, and a dynamic height respectively.
What I want is, to have an autolayout constraints setup, which allows my main UITableViewCell to resize as per it's inner UITableView.
Currently what's happening is, the inner tableView loads data perfectly, but does not resize as per the data, due to which the main cell can also not resize.
Any help in this regard would be appreciated.
Autolayout can not calculate the height of uitableview that inside cell because uitableview scroll inside there fore you can calculate the heigth required for your uitableview According to no. Of rows and content and then set this calculated height . in heightForRowAtIndexPath for main cell .

Resources