Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollsToTop does not work

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.

like image 711
Denis Kutlubaev Avatar asked Dec 07 '22 09:12

Denis Kutlubaev


2 Answers

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.

like image 78
Rahul Wakade Avatar answered Jan 03 '23 03:01

Rahul Wakade


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 UITableViewexplicit.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view  disableScrollsToTopPropertyOnMeAndAllSubviews];
    self.myTableView.scrollsToTop = YES;
}
like image 21
Dominic Sander Avatar answered Jan 03 '23 03:01

Dominic Sander