UIRefreshControl - beginRefreshing not working when UITableViewController is inside UINavigationController

后端 未结 15 862
梦如初夏
梦如初夏 2020-11-28 03:03

I\'ve setup a UIRefreshControl in my UITableViewController (which is inside a UINavigationController) and it works as expected (i.e. pull down fires the correct event). Howe

15条回答
  •  孤街浪徒
    2020-11-28 03:50

    In addition to @Dymitry Shevchenko solution.

    I found nice workaround to this issue. You can create extension to UIRefreshControl that overwrites method:

    // Adds code forgotten by Apple, that changes content offset of parent scroll view (table view).
    - (void)beginRefreshing
    {
        [super beginRefreshing];
    
        if ([self.superview isKindOfClass:[UIScrollView class]]) {
            UIScrollView *view = (UIScrollView *)self.superview;
            [view setContentOffset:CGPointMake(0, view.contentOffset.y - self.frame.size.height) animated:YES];
        }
    }
    

    You can use new class by setting custom class in Identity Inspector for refresh control in Interface Builder.

提交回复
热议问题