iOS: Make embedded Tableview "automatically" so big, it doesn't need scrolling but only the parent view does - ios

I want an embedded table view within a view. Depending on the user this table has 1-n rows. So the size varies. If I build it right now the table view has to be scrolled if n is too big. I however don't want the tableview scrollable, but I want to make it grow automatically so the user doesn't even see it's a tableview but instead the parent view surrounding the tableview should be scrollable. Or in other words, all rows of the table should be always displayed completely within the parent and depending on n the parent becomes scrollable. How can I accomplish this?

Related

How to get contents of container view to scroll in sync with parent tableview in Swift?

I have a table view controller which contains a view and below that, 2 container views. Each container view containing individual tableviews with some data (see diagram).
A segment control is used to switch between which of the container views are visible.
The content within the container views extend beyond the height of the main screen.
Currently the parent tableview controller is scrolling independently to the table views within the container views which is expected.
How can I sync the container views and parent tableview to scroll together?
Current hierarchy is shown in the diagram below:
Current view controller hierarchy
Usually having this kind of UX/UI is not a good idea. I personally hate this UX.
But to answer your question, you could observe for the contentOffset property of both child tableViews using KVO and update the parent tableView's contentOffset accordingly by doing the appropriate calculations.
Btw, you could use a regular UIViewController and UIScrollView as a containerView instead of the UITableViewController
The ideal approach for me is having a SINGLE tableView, and loading all the content dynamically. F.e. you could have the segment control (and all static data) in the tableViewHeaderView, and depending on which tab is selected you could update the content of the tableView accordingly by switching the array of the first tab's datasource to the second tab's, and vice-versa.
Even if the UI of the cells differs for both tabs, you could dequeue two different cells depending on the selected tab.

how to reduce spacing between multiple table views?

In this I had placed two table views on a single scroll view so that i had given constraints where as coming to landscape mode the space between the first table view and the other table view is increasing and is as shown here :
In portrait it works fine and there is not that much space can anyone help me how to reduce this ?
Bad idea using two table Views in scrollView. Use one tableView and make manipulate with items in dataSource which fill tableView, after items changed reload needed cells, and table view redraw.

How do I structure a table view to load halfway down a view?

I would like to make my UITableView load covering half of the window with a background view that starts visible, and as the window scrolls, is gradually covered by the table's cells.
Initially, I want to style is like so:
As the user scrolls, the cells will cover the background element.
The only way I could think to accomplish this would be to put the background element behind (and outside) a ScrollView (which is sized to fit over the background element and has a transparent background), put the TableView inside the ScrollView, and set the load coordinates to start the table far enough down. Is there a better way to accomplish my desired design?
I would prefer to avoid this layout because I would like to be able to easily add more cells dynamically as the user scrolls, ideally without having to deal with resizing the ScrollView.
You can take a view inside table view just above the table view cell and make its height whatever you want space in table view and make a outlet of that view. Then in view did load assign the view as table header view like this.
self.tableView.tableHeaderView = self.headerView;
This will be displayed exactly like you given and when user scrolls it will show the below cells and when you want you can change the frame of the header view and your header become invisible. You can do it whenever you want i mean if you want to change height on scrolling or if you want to change on adding more cells.

Is there a better way making horizontal scroll between different table views?

I need to implement the following feature:
I need to show a user list of many table views containing many cells each. One table view at a time. So user scrolls up and down within current table view and scroll left and right to go between different table views.
The way that I implemented it right now:
I have a scroll view occupying full screen.
Content size for this scroll view is three times wider then size of the screen.
In this content I layout three different table views.
Only second (middle one) table is displayed initially.
When user scrolls right or left I catch the end of scrolling event and reposition content back to the middle view and reload all three table views.
Am I missing something? Is there way to optimize it?
Here is a github liker for SwipeView. Just to implement datasource to setup tableViews on. This is useful for me.

How to dynamically resize table views inside a scroll view

I want to display two table views inside a uiscrollview and make the table views resize dynamically to fit their content. The table views should not be scrollable, hence the embedding in a scroll view. I have managed to resize the scroll view appropriately. The setup is as follows:
UILabel1
TableView1
..some extra space..
UILabel2
TableView2
I suspect that this should be possible with auto layout, but I need help to get started (I'm new to auto layout). Furthermore, I know that the labels could be added to the headers of the table views, but for now this will do. The data is fetched asynch over a network connection, so the table views need to be updated when the data is in.
Optionally, a couple of spinner could occupy the table view space until the data is ready to be displayed.

Resources