ScrollsToTop not working

I am using PPRevealSideViewController. I have two ViewControllers. The middle one is a subclass of SideSwipeTableViewController, and the left one is a subclass of UIViewController, which has a tableView inside it. Sample applications for the PPRevealSideViewController and SideSwipeTableViewController also support the scrollsToTop property for the UITableView, at least for the TableView, which is in the middle of the PPRevealSideViewController. But when I use both of these classes, scrollsToTop stops working.

I know this is a similar question, but I tried everything, I read all the messages that google gives me about this problem, but still could not solve it. So I decided to ask about it here, I have no ideas, even if what to do to make scrollsToTop work.

self.window.rootViewController = self.revealSideViewController; 

Where

 - (PPRevealSideViewController *)revealSideViewController { if (! _revealSideViewController) { _middleTableViewController = [MiddleTableViewController new]; UINavigationController *middleNavController = [[UINavigationController alloc] initWithRootViewController:_middleTableViewController]; _revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:middleNavController]; _revealSideViewController.delegate = self; } return _revealSideViewController; } - (void) preloadSidePanel { AppDel.systemTableViewController = [SystemTableViewController new]; AppDel.systemTableViewController.parent = self; [self.revealSideViewController preloadViewController:AppDel.systemTableViewController forSide:isLeftHanded ? PPRevealSideDirectionLeft : PPRevealSideDirectionRight withOffset:_offset]; } 

And I installed the following on this TableViewController system:

 _tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain]; [self.view addSubview:_tableView]; _tableView.scrollsToTop = NO; 

However, this does not help.

+4
source share
6 answers

If you tried all the solutions mentioned in similar threads here and failed to perform "scrollsToTop repair", you only need subclasses of the main UIWindow of your application.

 @interface CustomWindow : UIWindow @end @implementation CustomWindow -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { if (point.y <= 20) { //do something to scroll appropriate UIScrollView to top } return YES; } 

Use this in AppDelegate:

 #import "CustomWindow.h" @interface AppDelegate : UIResponder @property (nonatomic,strong) CustomWindow *window; @end 

This solution allows you to configure any UIScrollView of your application to scroll up, ignoring the general scrollsToTop mechanism.

All you need is to have a global link pointing to the β€œactive” UIScrollView at the moment.

+1
source

Scrolling up works only if there is only one type of scrolling (or any subclass of the scrolling type. In your case, this is a table view).

Even if several types of scrolling are visible, only one should have this property, then only it will work.

Also, if the delegate returns NO in scrollViewShouldScrollToTop, it will not work.

+7
source

With the next small UIView extension UIView I solved the same problem. Since this property does not exist only on UITableView , but also on UIScrollView and ancestors (e.g. UICollectionView ).

 @implementation UIView (UIViewPimp) - (void) disableScrollsToTopPropertyOnMeAndAllSubviews { if ([self isKindOfClass:[UIScrollView class]]) { ((UIScrollView *)self).scrollsToTop = NO; } for (UIView *subview in self.subviews) { [subview disableScrollsToTopPropertyOnMeAndAllSubviews]; } } @end 

I call this new method in the viewDidLoad -Method method and then set the property of the desired UITableView explicit.

 - (void)viewDidLoad { [super viewDidLoad]; [self.view disableScrollsToTopPropertyOnMeAndAllSubviews]; self.myTableView.scrollsToTop = YES; } 
+5
source

I hope this class can help. In my application, we have several webviews and scrolling. It makes everything a lot easier. :)

https://gist.github.com/hfossli/6776203

Good luck

+1
source

I thought I was cursed by the ghost of Jobs because I tried all possible solutions from all the related questions here on StackOverflow and I could not get my scrollviews to work together.

If none of the above answers work for you - make sure you don't have a subclass of UIScrollView or a subclass inside your table cells. Scrolling through your view of subviews and disabling scrollsToTop do nothing if your tableView has not yet loaded it as subviews.

The solution that worked for me was to create a public method disableScrollsToTop in my subclass of UITableViewCell that sets the scrollsToTop property of its scroll view NO .

The code I use (with generic names):

MYViewController.m

 - (void)viewDidLoad { // ... your initialization code [self setupScrollViewScrolling]; } - (void)setupScrollViewScrolling { self.horizontalScrollView.scrollsToTop = NO; self.tableView.scrollsToTop = YES; } // Note that I am using Xibs here, and your implementation for storyboards/xibless will be slightly different. - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath: MyTableViewCell *cell; static NSString *identifier = @"IdentifierForCell"; if (!(cell = [self.tableView dequeueReusableCellWithIdentifier:identifier])) { [[NSBundle mainBundle] loadNibNamed:@"MYTableViewCell" owner:self options:nil]; cell = self.tableViewCell; self.tableViewCell = nil; // ... cell initialization code [cell disableScrollsToTop]; } return cell; } 

And of course, disableScrollsToTop just

MYTableViewCell.m

 - (void)disableScrollsToTop { self.subviewThatScrolls.scrollsToTop = NO; } 

Another way (perhaps more extensible) can be done is the wrapping UITableView reloadData , and after the reboot, a recursive scrolling method is called, for example, that @Dominic_Sander says, although I did not check this solution, since I did messing with this problem.

0
source

I know this is pretty old, but hope this can help. Following the rule that scrollsToTop does not work if several UIScrollView or its subclasses are set to YES (the default value), a health check is probably worth checking who actually messed up this behavior. The simple method below is over the views of your view and registers the scrollsToTop value for the entire UIScrollView in your view. It is preferable to call viewDidAppear in your method.

 - (void)checkForScrollViewInView:(UIView *)view { for (UIView *subview in [view subviews]) { if ([subview isKindOfClass:[UIScrollView class]]) { NSLog(@"scrollsToTop enabled: %i in scroll view %@", ((UIScrollView *)subview).scrollsToTop, subview); } if (subview.subviews.count > 0) { [self checkForScrollViewInView:subview]; } } } 

This is really debugging code. When you find the scrollsToTop value for each of the subclasses of UIScrollView, make sure that only one of them is set to YES.

0
source

All Articles