Two UITableViews in one scrollview - ios

I want to make UIViewController, which has 2 UITableViews - one is content tableview, second is an comments section tableview.
Basically, It's an detail product VC, which has own UITableView for own content and second UITableView will be CommentsVC tableview.
Problem is that, I want to get them like one whole tableView (scroll together) (like 2 section style).
My first idea was to create UIScrollView container, which contains both UITableViews, but I think that there will be problem with reusing cells.
Example sketch

When you take tableview inside scrollview it creates problem in scrolling i.e conflicting scrolls of both scrollview and tableview as UIScrollview is superview of UITableView .
So it's better to take one UITableView with different section. One Section for your content and another section for comments.

Related

How to disable the scrolling of table view for first Section #iOS

I have two sections in my table view , I want to have scroll enabled for 2nd section and disabled for 1st section , how could I achieve it ?
A UITableView as a whole is a ScrollView so there is no way to only scroll one section. I'd suggest moving what is in the first section into a UIView, then placing a UITableView below that UIView that just has a single section that contains the views you had in the section of the view.
This way the top part will not scroll, but the bottom part will.
A way to workaround it is having 2 UITableViews, one with scrolling disabled while the other has it enabled.
You can disable scrolling on a UITableView on the Attributes inspector while it's selected. There's a whole section on the Scroll View the UITableView has, and in the second subsection there's a toggle for "Scrolling Enabled" which is on by default.
[Edit: I've just seen the other comment, and I'd still recommend 2 UITableViews if you are dealing with dynamic content. If the content from the 1st section isn't dynamic, you may use an UIView as it'll save a lot of time just by not needing to implement 2 UITableViews in a single UIViewController]
#vinay
Try this solution
Take a view at the top of view controller.
Below that view take tableview.
Set table style to Grouped. It makes sections of tableview scrollable.
In your case I would use Section Header for the second section and make that header as customView.
You need to call the following functions:
1) viewForHeaderInSection
if section == 2 {
... customize your header view
}
2) heightForHeaderInSection
if section == 2 {
... set height
}

Can we add tableview to cell?

I want to customize my tableview. I want to add another tableview in cell. Can we add tableview in cell of another tableview?
Please give me some ideas.
You can embed a UITableView into another UITableView's cell, but due to potential issues with the embedded UIScrollViews it is not recommended.
If you feel like you need a table in a table, first consider if it is not possible to achieve the desired behavior by using sections and cells in the sections (a section in a table might represent the top tableView's cell, and cells in the given section would represent the embedded tableView's cells).
There is no problem with adding a UITableView into a a UITableViewCell, since both of them are UIViews its simply would be translated to adding a subview to a view...
However, keep in mind to consider the following issues:
1- From a user experience perspective, that would be a vertical scroll view inside another vertical scroll view (are you ok with that?).
2- For each cell -in the main container table view-, you would need to handle the table view delegates/datasources. For understanding the logic of how this could be done, you might want to check:
Is it possible to add UITableView within a UITableViewCell.
Putting a UICollectionView in a UITableViewCell in Swift: although it is about adding a UICollectionView inside the cell, it helps to gain the logic of how to achieve such a task.

How to insert a UITableView inside a UITableViewCell and make the UITableView not scrollable?

The above pictures are from the Blue Apron app. This specific page has a scrollable view (let's just say UITableView ) and within that UITableView they have this one section called Instructions which has cells numbered (1,2,3, etc.) as seen in the pictures above.
I assuming inside of that Instructions Section they have a UITableView to display those cells (Cook the freekeh, Prepare the ingredients, etc). But how do they make that UITableView unscrollable and make it scroll with the main UITableView?
I basically want to know how they get those list of views in that instruction section within that main UITableView without having it scroll.
Does anyone have any ideas or am I interpreting this completely wrong and there is a better method?
You can follow this you tube tutorial created by me.
https://www.youtube.com/watch?v=yQ1DfCI93pU
Just you need to replace collectionview with tableview.
Hope it will help!.

One section of the view controller is still and one section horizontally scrollable

I would like to construct a view controller where one section of the view controller would be still and one section scrollable.
Both sections have headers where as well, one is still and one is moving along with the content in the section.
I do not want the cells in the section to be scrolled separately. All cells should move at the same time along with the header.
I have added an image to make my point little more clearer.
Use UICollection View for both view and disable scrolling for one view and enable scrolling for another view
you can probably add to your UIViewController view a UITableView on the left with fixed size (for example 150px) and vertical scroll disabled and a UICollectionView with horizontal flow and ,if needed a, with custom UICollectionViewLayout (but i think that you just need the classic UICollectionViewFlowLayout) for the right part that fits the remaining space.
Here you can find the component's documentation:
https://developer.apple.com/reference/uikit/uicollectionview
https://developer.apple.com/reference/uikit/uitableview

Scrolling Views Along with Collection View Cells

On my view controller I have 1 collectionview underneath 2 views at the top of the view controller I set the collection views height based on the size of the views so the collectionview is big enough that it doesn't need to scroll. All 3 views are inside of a scrollview so that I can scroll the views and the collection cells seamlessly. This feels very inefficient but i can't think of another way of providing this sort of seamless scroll between the views and the collectionview. Is there something else I can do to achieve the same or at least similar result?
EDIT: https://gyazo.com/8e5febea0974b0e6e0660f1714d67cbc this will hopefully explain it better. label is the view inside of the scrollview above the collectionview and four buttons are collectionview cells. Now if I add 20 buttons instead of only 4 I can scroll the collection view but it won't scroll with the label. This might also help explain what I'm trying to achieve - http://jsfiddle.net/hDwPH/
Ignore This Dummy Code
From the screen shot, I assume that your view controller consists of
1 UILabel
Multiple UIButtons
Only 1 item per row
If so, you should consider using UITableView instead. The UILabel will be section header, The UIButtons will be the rows (UITableViewCell). So your UITableView consists of 1 section, 20 rows.
If you want your UILabel to float along with the UIButtons, set the
UITableView style to UITableViewStyleGrouped
If you want your UILabel to remain fixed, set the UITableView style to UITableViewStylePlain

Resources