how to load two different dynamic tableview cells in same UITableViewVibrantCell - ios

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

Related

UITableView: How to know when all the cells of TableView with dynamic cell heights are resized?

The problem I am facing is that when I send a data to UITableView then I send a command to scroll the table to bottom. If cell heights are constant then my scrollToLastCell takes to last cell but with dynamic cell heights it doesn't always takes to last cell.
I want to know is there any way when I can be sure that all cells of my tableView is finished resizing and then I trigger scroll to bottom?
In the Docs Apple states
Important
If your table view includes self-sizing cells, headers, or footers,
you must provide estimated heights for those items.
https://developer.apple.com/documentation/uikit/views_and_controls/table_views/estimating_the_height_of_a_table_s_scrolling_area
Given that, I'd suggest you to go ahead and use tableView(_:estimatedHeightForRowAt:) method

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

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.

TableView reload not setting UITableView section height

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.
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.

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