Can't get scrollsToTop working on iOS7

前端 未结 6 463
我在风中等你
我在风中等你 2020-12-29 04:15

I\'m targeting iOS7 in my latest app, and tapping on the status bar doesn\'t seem to scroll a tableView or collectionView to the top.

I\'ve set self.tableView.

6条回答
  •  没有蜡笔的小新
    2020-12-29 05:16

    If your table cells are dynamic, remove the following:

    - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
    {
        return YES;
    }
    

    Create a new function as follows:

    - (void) disableScrollsToTopPropertyOnAllSubviewsOf:(UIView *)view {
        for (UIView *subview in view.subviews) {
            if ([subview isKindOfClass:[UIScrollView class]]) {
                ((UIScrollView *)subview).scrollsToTop = NO;
            }
            [self disableScrollsToTopPropertyOnAllSubviewsOf:subview];
        }
    }
    

    Call the function above in - (void)viewDidLoad

    [self disableScrollsToTopPropertyOnAllSubviewsOf:self.view];
    

    Now enable ScrollsToTop for your table view as follows:

    [myTableView setScrollsToTop:YES];
    

提交回复
热议问题