UIRefreshControl not showing spiny when calling beginRefreshing and contentOffset is 0 [duplicate]

邮差的信 提交于 2020-01-11 00:44:07

问题


I am not able to see the loading spinner when calling beginRefreshing

[self.refreshControl beginRefreshing];

My UITableViewController subclass uses a UIRefreshControl

// refresh
    UIRefreshControl * refreshControl = [UIRefreshControl new];
    [refreshControl addTarget:self action:@selector(refreshTableView) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = refreshControl;

It is working perfectly with user interaction (when the user drops the table down), then the spinner is visible.

But when i call beginRefreshing on viewDidLoad, I don't see the spinner (only when i drag the table down).

Notes:

  • self.refreshControl reference is right

  • reloadData or endRefreshing is not called immediately after beginRefreshing, but there is a long time delay (loading data through network), so I am not canceling the beginRefreshing.

Edit : This only happens when the contentOffset property of the tableView is 0 and i call [self.refreshControl beginRefreshing]. Bug? Feauture?


回答1:


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){

        }];

    }
}



回答2:


Your fix looks good, But I don't think this as a bug.

When beginRefreshing method is called manually,

When there is no row / cell available it makes sense for refresh control appearing automatically. But when there are some cells available, and when we call begin refresh manually (A scenario where we refresh periodically based on timer) then It should not animate / change the content offset as it will distract the user if he is seeing / reading content in some visible cell.



来源:https://stackoverflow.com/questions/16120797/uirefreshcontrol-not-showing-spiny-when-calling-beginrefreshing-and-contentoffse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!