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

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.

Related

UICollectionView Scrolling the ViewController

Im trying to implement a CollectionView inside my viewController.
And it works just fine.
The problem Im having is that the CollectionView scrolls inside the Parent controller.
I wish to make that if you scroll the collection view - the whole view is scrolled and not just the collection view bit.
I tried disabling scrolling on the Collection View but then nothing is scrolling anymore.
So how would I go about setting the collection view, so that once you scroll on it the whole page scrolls and not just the collection view scrolling inside the parent view controller?
It should be simple, and you've done one right thing already.
Disable scrolling of your collectionView (or tableView, in the future just in case you'll use it, they're basically the same).
Add your collectionView (or tableView) inside a scrollView.
That scrollView is of course in your controller's view.
Make sure every constraints are set properly.
You might need to get the size of your collectionView (say height), and set that height value to the constraint height of your collectionView.
These answers of mine in the past should help you:
https://stackoverflow.com/a/52657995/3231194
https://stackoverflow.com/a/54211275/3231194
https://stackoverflow.com/a/53971539/3231194
Voila. The only scrolling enabled is your scrollView that contains your collectionView (or tableView).

Swift: Did Tumblr add a UICollectionView in a UIScrollView?

I've been trying to replicate this effect for a couple days which was inspired by Tumblr.
I've previously asked questions on here with different approaches of the same problem but to no avail. I'm just curious as to how the engineers at Tumblr created a horizontal collection view, with two vertical collection views, and is able to scroll down without affecting the view above (without resetting the position of the view when you scroll vertically in a different tab).
Header Views
I tried this, but the header view was isolated and I had to scroll to the right to see the collectionView cells. This did not work.
Changing the topLayoutConstraint constant of my UIView (not cv header) with respect to the contentOffSet of the vertical collectionView.
This almost got the effect I wanted, except that when I scrolled horizontally, there was a huge gap between my collection view and if I scrolled in that new tab, the UIView would appear again because, again, topLayoutConstraint gets scrolled up depending on the contentOffSet of my vertical collectionView contentOffset.
Changing the position of the UICollectionView frame, and scrolling the super view up simultaneously with NSNotificationCenter.
Alas, this method did the same as method #2, except that the vertical collection view cells scrolled faster than the super view.
I ran out of options to make this work so I will show you in detail what's attempted to be replicated (also note the scroll bar on the right):
Note when I scroll down the first tab. I switch, and then scroll down further. Originally, as I've said, there would be a gap between the second main CV, and when I scrolled, the view would reposition as if were scrolling up again. On here, the view on top keeps going up. So I'm curious as to what method Tumblr engineers used to do this. UICollectionView inside UIScrollView? Other suggestions?
I believe there is no UICollectionView involved. It looks like UIPageViewController and each its page is a UITableView.
Perhaps the UIPageViewController sits in a UITableView as well - the header also moves up when you scroll. This main table has only one cell (and a header) which is occupied by the UIPageViewController.
Hope it helps.

Adding a Scrolling Subview to a UITableView (NOT a Cell)

I'm creating my views programmatically. I have a UITableView in my UIViewController subclass that I want to add a scrolling subview to that is not a cell. I want to add some text-based subview to the UITableView that scrolls with the table and starts out above y=0 so the user will only see it if he pushes the table down. That is, it should reside above the first section of my table. If it helps for visualization, I intend to make something similar to those "scroll down to refresh" features and want some indication to the user that scrolling down causes a refresh. Is there any way to do this without something messy like using another UITableViewCell to represent it or abusing the UITableView delegate methods to move a view around whenever the user scrolls?
Simply using [tableView addSubview:] in my viewWillLoad only makes it appear for a split-second then disappear once the table data is loaded. This seems weird to me because UITableView is a subclass of UIScrollView, which is meant to hold other views in it. Using [tableView.backgroundView addSubview] does nothing.
P.S. Why not use a UIRefreshControl for this? I'm still undecided but leaning towards not using one because I don't like how slow that spinning wheel "feels" when the refreshes are usually very very quick. I've been looking at other options like flashing the background subtly and only showing a wheel if it's taking a longer time than usual.
I You can implement pull to refresh with only a table view
To do this using the scroll view delegate, since tableview is a subclass of scroll view.
Set view controller to be the tableview delegate and implement
(void)scrollViewDidScroll:(UIScrollView *)scrollView
When scrollview content offset y value passed a point, add a label to the viewcontroller.view not tableview. When you scroll back or release, remove the view.
You might also be able to add label to the table view and set the frame origin to negative y value, so when you pull the label will move into view (Never tested this do might not work)

ios : tableview not appearing in subview of a scrollview

I have a scrollview with multiple views.Enabled horizontal scrolling.Each view contains a tableview.I have page control in scrollview. when i drag horizontally, the views are appearing without tableview except the first view. Please give me suggestions.
Make sure if setContentSize to your scrollview means scrollview content size is the size of your main view.
When you scroll to next view or if you scroll to view displayed for first time, make sure you reload table. You can implement his through delegate and protocols. For example, when you scroll to second view for first time, then controller should call some method on subview to reload its table.

Sticky UITableView, unnecessary horizontal bar is visible, and I can't scroll to the bottom of the table

I've created a UITableVIew and it is a subview of a UIView. There are three issues that i'm having and it is only occurring on iOS 4 devices:
1) The table doesn't bounce when the view hits either the top or bottom of the table while scrolling. The vertical bar doesn't shrink either, it feels sticky and it is very much acting like an Android table view. I've tried enabling the bounce property but that doesn't make any difference.
2) The horizontal scroll bar appears when the view is scrolled down to the bottom of the table. This shouldn't appear since the table view's contentSize has been set correctly. It does eventually disappear when the contentSize is set 20 pixels less than what it should be.
3) I can't scroll to the bottom of the footer view, and only half the footer view is visible.
I've added a UITableView as a subview to other views throughout my project and this has never occurred, and so i've copied the way that I create other UITableViews, but still no luck.
Any suggestions would be greatly appreciated.
Thanks,
Ankur
I worked out the problem. The problem is a little strange, although i had a feeling that the way i was coding was a little messy.
I am subclassing a View, and the parent view has a layoutSubview method, which is only calculating and setting the frame for a table view subview. In the subclass, i had to override layoutSubview for the same reason as the values for the table view's frame need to be different. This means that the table view's frame was being laid out twice, once by the parent class and a second time by the subclass. It seems that iOS 4 doesn't like this, and i should only set the frame once per subview per layoutSubview call.
Now i've created a layoutTableView method, which is called from the parents layoutSubview, and i've overridden layoutTableView in the subclass. Therefore the table view's frame is only being set once.

Resources