I am using PPRevealSideViewController. I have two ViewControllers in it. The middle one is a subclass of SideSwipeTableViewController and the left one is a subclass of UIViewController, that has a tableView inside it. Example apps for PPRevealSideViewController and SideSwipeTableViewController are both supporting scrollsToTop property for UITableView at least for the TableView that is in the mid of PPRevealSideViewController. But when I use both of these classes, scrollsToTop stops working.
I know this is similar question, but I have tried everything, I have read all posts, that google gives me about this problem, but still couldn't solve it. So I decided to ask it here, I don't have any ideas even 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 set in this systemTableViewController this:
_tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
[self.view addSubview:_tableView];
_tableView.scrollsToTop = NO;
However, it doesn't help.
Scroll to top works only if there is only one scroll view(or any subclass of scroll view. In your case it is table view) is visible.
Even if there are multiple scroll views visible, only one should have this property set then only it will work.
Also if the delegate returns NO in scrollViewShouldScrollToTop, it will not work.
With the following little Extension of UIView
I solved the same issue. Because these property doesn' ´t only exist 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 these new method in the viewDidLoad
-Method and then I set the property of the desired UITableView
explicit.
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view disableScrollsToTopPropertyOnMeAndAllSubviews];
self.myTableView.scrollsToTop = YES;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With