How to fire scrollsToTop when UITableView is nested in UIScrollView

I was wondering if anyone will be able to get away with scrollsToTop (or in any other way) for a UITableView from a user who clicks on the status bar when a UITableView is nested inside a UIScrollView that also observes this function? I know this is probably not a good practice, but in this case the UX type invokes this hierarchy type.

In any case, I saw a whole bunch of suggestions, from private methods (obviously, it will not happen) to adding fake windows to the status bar (it also will not happen).

+5
source share
4 answers

So the answer here is two times:

  • UIScrollView ( , UIScrollView, UITableView) UIView, scrollsToTop YES. , , ,

    , :

    scrollView.scrollsToTop = NO;
    tableView.scrollsToTop = YES; // or not set
    
  • UIScrollView scrollViewShouldScrollToTop: return YES, UIScrollView UITableView.

, scrollsToTop.

+13

, , . , , ToTop. , , . , , viewDidAppear. , , 0.

-(void)inspectViewAndSubViews:(UIView*) v level:(int)level {

NSMutableString* str = [NSMutableString string];

for (int i = 0; i < level; i++) {
    [str appendString:@"   "];
}

[str appendFormat:@"%@", [v class]];

if ([v isKindOfClass:[UITableView class]]) {
    [str appendString:@" : UITableView "];
}

if ([v isKindOfClass:[UIScrollView class]]) {
    [str appendString:@" : UIScrollView "];

    UIScrollView* scrollView = (UIScrollView*)v;
    if (scrollView.scrollsToTop) {
        [str appendString:@" >>>scrollsToTop<<<<"];
    }
}

NSLog(@"%@", str);

for (UIView* sv in [v subviews]) {
    [self inspectViewAndSubViews:sv level:level+1];
}}

.

→ > scrollsToTop < < , , .

+12

One thing that helped me fix this issue:

  • Confirm that everyone else UIScollViewin the view hierarchy is set toscollsToTop = NO
  • Adding subview controllers as child view controllers using It is addChildViewController:not enough just to add the subview view to the parent view.
+1
source
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[gridTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];

Hoping to help you :)

-2
source

All Articles