Scrolling issue when UITableView is inside ScrollView - ios

I have a UIScrollview covering the entire UIViewController's main view. Inside UIScrollview is a content view that allows the UIScrollview get the scrollable content. Inside the Content View of Scroll View is a UITableView.
I'm not being able to scroll the UITableView. Instead the vertical swipe is passed directly to the ScrollView causing it to scroll. How can I make the UITableView scroll inside the UIScrollview?
I have read the answers of many similar questions but none of them solved my issue
Question 1
Question 2
Question 3

You need to set correct constraints (or frames) for UITableView (size of TableView must be less, then contentSize for scrolling).

Make sure that's your constraints of UITableView related to UiScrollView
Disable UITableView scrolling
Make your scollView center Verticly to the main container and change the priority of constraint to 999
Hope that help you

Related

How to make a Horizontal and vertical scrolling TableView in iOS using storyboard?

here is my design structure
I was wondering about creating a horizontal and vertical scrolling tableview. I have tried a tableview inside a scrollview but I failed miserably. What to do?
I use swift4 but I wanted to do in storyboard.
The nature of content is like an excel sheet with lots of horizontal and vertical scrolling rows and columns of data.
Actually you can do this using a hack. Put the tableView inside a scrollView. Then you should give a dynamic width to the tableView by specifying a width in storyboard for tableView or any child view of that scrollView(So we get the horizontal scrolling).You have to adjust some constraints depending on your requirement
Mine worked fine but as many users have said try a collection View if its easy
Note. There is a default scrollView within a tableView, So adjust your height of tableView in a way so the scrollView of tableView work and not the parent scrollView, while scrolling from top to bottom
Instead of using TableView try using collection view, there you can use horizontal and vertical scrolling using storyboard?
Try to use collectionview instead of tableview.
If your requirement demands use of tableview anyhow, then you can use tableview within scrollview.
In tableview within scrollview approach, you need to distinguish your parent scrollview as well as tableview's scrollview. Try to differentiate parent scrollview and tableview's scrollview with different tags. Because both scrollview will call delegate methods of viewcontroller, if implemented. Just check tag of scrollview in all delegate methods of scrollview and perform action accordingly.
As per my understaing you want a view which you want vertical scroll view and horizontal inside it.
So here my suggestion is to use UITABLEVIEW for vertical scrolling and UICOLLECTIONVIEW for horizontal scrolling inside tableview
Both will work fine

UITableView inside UIScrollView - Cell not clickable

I have a problem with a UITableView not detecting touches.
In an iPhone-only app, I have a UIViewController, which containts:
UIScrollView
UIView (let's say a content view)
Some labels
UITableView (last)
The labels have a dynamic height, because they contain some text that I must retrive from the web, so I'm using auto layout.
I'm setting the content size of the UIScrollView inside the viewDidLayoutSubviews method, and I'm doing this by summing UITableView.frame.origin.y and its height.
Here comes the problem: when the labels contain only some words and the UITableView does not exceed the iPhone screen size, everything works ok. But when they grow, and the UITableView gets pushed down, when I scroll down I can't click on the cell anymore. Also, if when loading the view the table is half visible and half not, I can click the visible cells, but if I scroll down, I can't click the others.
I'm using swift 2 and Xcode 7.
Here is an example:
Clickable:
Unclickable:
Do the following thing:
yourView.clipToBounds = true
Now, if UITableView does not appears means your UIView is not same bigger to hold down UITableView.
Make sure that your UIView height is bigger to hold the contents in it and then try to tap on it.
Updated:
If you are using AutoLayout, then do the following thing.
Give the fix height to UIView
Take the outlet of height constraint of UIView
Now, in viewDidLayoutSubviews change the constraint of UIView to UITableView contentSize height.
self.heightConstraint = self.tableView.contentSize.height
Let me know, if this helps!
Adding some info to the #Rémy Virin's answer here:
From Apple Documentation, you shouldn't embed a UITableViewinside a UIScrollView.
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Addition:Solution Since you want to scroll the content above table also, the one solution is place a Header View for the Table and place the Content over there to make it Scroll along the Table View.
If you use Autolayout, no need to specify contentSize to UIScrollView as it will automatically expand by taking the height of its subview.
In your case, increase the height of the Base UIView (content view as mentioned by you) which holds the tableView when the tableView height increases.
UITableView becomes unresponsive when it extends below its container view.

Pass scroll between UIScrollView and embed UICollectionView

Here's my architecture.
I have a UIScrollView with some UIView's added in.
At the end on my scrollview i have a UICollectionView (embedded in my scrollview) in which i loads many data. I had to use a UICollectionView in order to reuse the multiple views displayed.
What i want is keep a smooth scroll when the user scrolls to the bottom of the parent scrollview and continue scrolling in the UICollectionView.
What i've made now is set the size of my UICollectionView equal to my UIScrollView Size and i've disabled bounces on both.
But i can't have a smooth scroll. When i reach the end of my UIScrollView, the scrollview's stop and then i have to re scroll on my UICollectionView
Not sure if it's really clear.
You should not normally "pass scroll" between elements. What you need to make sure is that the UICollectionView's frameSize is equal to its contentSize, meaning its frameSize expands as much as its contents so that all of its content is visible without having to scroll. Then your UIScrollView will handle the scroll and show the contents of your UIViewController by scrolling just itself.

UITableview frame changes after scrolling thanks to Autolayout

I'm working on a application where I have a UITableView inside a UIScrollview.
The TableView will display current games players are in, its inside a UIScrollView. I dynamically add cells to the UITableView for each game, but when I scroll the UIScrollView, the tableview inside it snaps back to its size set in the storybuilder.
This is because of autolayout, when I disable it, it doesn't happen anymore. However I do like autolayout for other views in my app. So my question is, how can I fix this problem?
Maybe someone can help me get on the right track.
Thanks
EDIT
I think I must explain my situation more, I will use an image where I can display what is happening
Explanation
Before and after scrolling.
As you can see I use the scrollview because there can be many games, so you'll have to scroll down to see them all. The TableView is just to hold the data, scrolling is disabled on that. After scrolling the TableView that says "JOUW BEURT" snaps back to its size set in the Storybuilder. This is because of auto layout like I said, but I don't know how to fix this.
You shouldn't put a tableview inside a scrollview as a tableview itself contains a scrollview and causes issues just like you are seeing when you have a scrollview inside a scrollview.
Remove the scrollview and this should fix your issue. If you are wanting to put content above the tableview or where you scroll down to view the tableview cells etc, consider adding a tableview header view that is added above the tableview.
Why did you place UITableView inside UIScrollView?
Check below
Check your constraints of UITableView and UIScrollView
Placing UITableView inside UIScrollView is somewhat strange
EDIT
You will just need to remove the scrollview and enable scrolling feature of the tableview. that will fix it
UITableView is already a subclass of
UIScrollView

UITableView not scrolling inside of UIScrollView

in my view controller I have a ScrollView for content adaptation on various devices .. I need to insert a tableView inside the ScrollView but I noticed that my tableView not scrolling when it is inside a ScrollView. Can someone help me figure out how to fix this?
If you want your table view to scroll set the content size of scroll view less than that of your table view.

Resources