How to use scrollview to a viewcontroller with UILabels and TableViews - ios

My TableView rows varies in size. I want to scroll it down.. But I don't know how to use a scrollview.. I've added a scrollview below the other content views.. I also assigned an IBOutlet, but i don't know what to code or something.. Also it works but it bounces back to the viewable screen only, I need to hold the screen to steady the view.. How do I fix this?

Related

Nested UIScrollviews behaving strangely

I have the following autolayout-driven setup:
Main viewController, with a scrollview inside it. Scrollview pinned to superview edges. This one scrolls up and down.
A few normal, fixed size views at the top of the scrollview
Another scrollview. This one scrolls left and right. The second scrollview contains a couple of tableviews, side by side. The idea is that the user can switch between them. They both contain a handful of cells, all the same width as the screen and 72pts tall.
The problem I'm trying to solve is that the tableview contents are not the same size. The left one has say, 6 cells, and the right one has 3.
My first approach was to dynamically change the second scrollview height to match which ever tableview was currently visible. What ended up happening was that switching between the two tableviews (by doing setContentOffset:animated:) went extremely wrong if animated was set to true - it would adjust the content offset so everything was offscreen. In fact it would set the content offset to and then as I switched, about a dozen times, then it'd reset. It was weird, I gave up.
Now I'm trying to just adjust the content inset of the main scrollview to offset the gap in the content of the current tableview, and it's also being weird. When I set the bottom content inset in viewDidLoad, it works fine. When I set it at the time the tableview becomes current, it does nothing.
What gives? What scenarios would lead to these view interactions not behaving properly?
Use different tableViewController for each table.
Embed them in pageViewController.
Add those few normal, fixed size views at the top of the pageViewControllers view.
Conform scrollViewDelegate in pageViewController.
Pass scrollViewDidScroll from tableViews to pageViewController.
Set tableViews inset to match those fixed size views at top.
Change height according to the scroll.
This is the way you can achieve the functionality you want.
I hope it helps.

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

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.

iOS 7.1 Why is my UIScrollView scrolling away on showing keyboard?

I have a UIScrollView designed with IB.
UIView
UIScrollView
UIView
UITextField
UIButton
...
If I tap on the text field the view scrolls away towards the upper left corner of the screen before the keyboard is appearing. The space above the keyboards remains empty. I can scroll back the view if I drag in this empty space.
I have googled around, but found only postings where users want to scroll UIScrollView. I want the view to stay where it is.
Thanks in advance for any suggestions.
Here's what happened.
You designed the whole thing in Interface Builder.
The scroll view was not scrolling, so you set its contentSize in code to the size of the scroll view's primary subview (what I like to call the content view).
The scroll view was still not scrolling, so you munged the content insets - and this caused the problem that brought you here.
Your mistake was (3). Instead, you should have thought more about (2), i.e., why isn't my scroll view scrolling even though I have given it a nice big content size?
The answer is that, in a storyboard or xib that has auto layout turned on, that's not what you do. What you do is use constraints from the content view to its superview (the scroll view), on all four sides. Set the constant for all four constraints to zero. This causes the content size to match the size of the content view, automatically.

UITableView stops scrolling enough after I add/remove a view to the superview of table view

Here is the problem that I'm facing. I have UITableView inside main view. When user taps menu button, view is added to the view hierarchy of superview, and this view covers all screen, except the menu button. That is I call
[self.view insertSubview:self._menuView belowSubview:self._menuButton]
After user clicks the menu button again I call
[self._menuView removeFromSuperview]
However, after this, the UITableView stops scrolling, actually it scrolls, but just a little, couple of pixels, and then bounces back to the location on which it was before I inserted _menuView. I've monitored the menu hierarchy after inserting and removing the _menuView, it is actually removed, and also there is no view which covers the UITableVIew, so there is no chance that some other view steals touches from UITableView. What can be the problem? Any ideas?
EDIT 1: I've noticed besides not being able to scroll, another strange thing happens. When I show menuView, the tableView is scrolled to top, without animation. (the menuView is half opaque only, so I can see the tableView underneath it)
EDIT 2: I've monitored contentSize and contentOffset of tableView before and after inserting _menuView, the reason for not being able to scroll is that somehow contentSize is being changed.
TABLE VIEW BEFORE INSERTING MENU - contentSize:{Width=320, Height=10519} contentOffset:{X=0, Y=3980}
TABLE VIEW AFTER INSERTING MENU - contentSize:{Width=320, Height=44} contentOffset:{X=0, Y=0}
As You can see, the height is changed to 44 that's why I'm not able to scroll. And Also, as I've said in EDIT 1: tableView is scrolled to top - so as you can see contentOffset is also zeroed. Any ideas why content size changes automatically?
Thanks in advance.
i think there is problem with your tableview frame. right after removing subview, try to set frame of your tableview at its original frame.may this will solve your problem
Content in the UITableView organized automaically and designed only to show cells & header/footer elements. To proper working you should wrap your table into parentView and add your menu to that parentView rather than to the UITableView. You can also try to call reloadData method on table since it can restore the content size of the view.

Resources