UITableview frame changes after scrolling thanks to Autolayout - ios

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

Related

Scrolling issue when UITableView is inside ScrollView

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

Mixing UIScrollViews and UITableViews

If you look at the Featured tab of the Apple App Store app on an iPhone 6, there is a unique UI layout that I can't figure out how to replicate.
At the very top there is a navigationBar. Below this there is a UIScrollView that animates through a number of featured items. Below this is what appears to be a UITableView with a number of custom programmed cells.
My first guess was that the UIScrollView at the top was added to a custom cell at the top of a UITableView. If you swipe up the UIScrollView moves with the objects below like it is a cell. You can see that the vertical scroll indicator starts at the top of the UIScrollView.
The part that is unique is that if you swipe down, the objects below the UIScrollView move down like a UITableView and the UIScrollView stays in place. This means that the UIScrollView is not a custom cell at the top of a UITableView.
I tried making this work a number of different ways but I can replicate this. Does anyone know how this can be done?
You can use a tableview header,the header is a scrollview
If you scroll tableview up,just use tableview default behavior,the header will scroll up.
If you scroll down,use UIScrollViewDelegate to calculate the tableview header new frame,and adjust it.So it remain at top
Not sure if I got you correctly, you may use UICollectionView as vertical scroll. Then, you create a custom UICollectionViewCell, each with horizontal scroll.
I haven't tried it though but done something similar to this. Hope you find a way!

scrolling tableview upwards and keeping tableview in complete scroll view

In this I need scroll complete tableview to upward and tableview should stay upwards until user again scrolls down. It should come back to its original position.
Update
I need to scroll the tableview top and bottom on a image
From Apple documentation it's not advisable to add tableView inside scrollview(Reference).
Now according to design of your screen either you can have one tableView and in header of that tableView you can add all static content.Reference
or if your design must have tableView inside scrollView then this SO question maybe helpful to you.
I'd prefer first choice if possible.
By the way if you can fix the height of tableView then you can implement tableView inside scrollView easily.

UIScrollView behavior is different in iOS8

I have the following layout
So it's basically a scroll view that occupies whole screen. Content size is set to triple-width and same height. Inside the scroll view - there is container view and three table views - one per page. Only middle table view is visible initially.
This allows me to use scroll view horizontal scrolling to navigate between the tables and vertical scrolling inside the middle table.
I know that Apple doesn't really recommend putting UITableView inside UIScrollView, but in this particular case I don't know how to implement it differently, and until iOS8 everything was working fine.
UIScrollView would not recognize any vertical scrolling (since content height was equal to scroll view height) and these gestures were passed directly to UITableView.
But starting in iOS8 - this getting broken. UIScrollView would allow some vertical scrolling and basically intercept scrolling gestures sent to UITableView.
I created a simple project that works fine in iOS7 but is broken in iOS8. Anybody has any idea how to fix this problem?
Link to the project: https://dl.dropboxusercontent.com/u/6402890/TablePaging.zip
I haven't been able to solve this and as I mentioned in comments had to re-write logic using built-in UIPageViewController class.
If I change the Class of your ScrollView in Interface Builder to UIScrollView, it fixes part of the problem. Now just the UITableView goes up and down, and I go left-and-right, but haven't gotten rid of the space at the top.

UITableView Not Scrolling

I have a tableview which will not budge when touched. It is very confusing to me. It is the most recently added subview (I checked - it is the last entry in my view's subviews array) and for some reason it just won't scroll up or down. If I tap multiple fingers wildly on the tableview it will one in a while highlight the cell under one of my fingers, but it will not scroll even a little. I have set the number of rows to 100 (many more than are visible on screen) and I have set the 'bounces', 'scrollEnabled', and 'userInteractionEnabled' properties to YES.
I know that I have not provided much to go on here, but if anyone could at least give some tips on how to go about debugging this I would be very grateful. Can I log from within the tableView gestureRecognizer handling method? Can I test where my touches are going?
Please help!
Thanks.
A TableView is basically a specialized ScrollView. If it's not scrolling, it seems to me it could be one of two things. Either something is on top of the TableView and is capturing the gesture events before the TableView can get them, or You have set the bounds and contentSize incorrectly. For a TableView or ScrollView, the bounds of the view should be the visible area, and the contentSize (should be handled by the TableView without you needing to do anything) is the size of all the cells in the Table.
So I would check the bounds of the table view and make sure you are setting that to the contentSize, since that would cause it nor to scroll.
Just to make sure it's on the top, try calling
[view bringSubviewToFront:tableView];
In my case tableview "User Interaction" was disabled. I just enabled it & works.
In my case, tableView "canCancelContentTouches" was not enabled. I set it to true in the storyboard.
Can you check the frame of the parent on which the tableview is added? Make sure the parent view have correct frame to include the table view. I have faced this issue sometime back my table view was not responding to touches and there was some problem with frame size. Also do check the bounds and frames of your tableview
-anoop
Please check tableview scroll is enabled.
I just hate XIB and Storyboard. After 30 mins of debugging it come to know that scroll was not enable in XIB.
Thanks
Basically, Table view is just a kind of scrollview. So in case it is not scrolling You should be sure that if the frame size of your table view is less than the contentSize of your table view. For this just log the frame and content size of tableView's scroll view. If you found that frame size is greater or equal to your content size, just correct your layout constrain of your view. And I hope it will work.

Resources