UIRefreshControl - beginRefreshing not working when UITableViewController is inside UINavigationController

后端 未结 15 770
梦如初夏
梦如初夏 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 04:04

    UITableViewController has automaticallyAdjustsScrollViewInsets property after iOS 7. The table view may already have contentOffset, usually (0, -64).

    So the right way to show refreshControl after programmingly begin refreshing is adding refreshControl's height to existing contentOffset.

     [self.refreshControl beginRefreshing];
     [self.tableView setContentOffset:CGPointMake(0, self.tableView.contentOffset.y-self.refreshControl.frame.size.height) animated:YES];
    
    0 讨论(0)
  • 2020-11-28 04:06

    For Swift 4/4.1

    A mix of existing answer do the job for me:

    refreshControl.beginRefreshing()
    tableView.setContentOffset(CGPoint(x: 0, y: tableView.contentOffset.y - (refreshControl.frame.size.height)), animated: true)
    

    Hope this helps!

    0 讨论(0)
  • 2020-11-28 04:10

    See also this question

    UIRefreshControl not showing spiny when calling beginRefreshing and contentOffset is 0

    It looks like a bug to me, because it only occures when the contentOffset property of the tableView is 0

    I fixed that with the following code (method for the UITableViewController) :

    - (void)beginRefreshingTableView {
    
        [self.refreshControl beginRefreshing];
    
        if (self.tableView.contentOffset.y == 0) {
    
            [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^(void){
    
                self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);
    
            } completion:^(BOOL finished){
    
            }];
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题