iOS 10.0 UIRefreshControl not showing indicator

杀马特。学长 韩版系。学妹 提交于 2019-12-18 11:52:00

问题


I am using a UITableView Which has a Pull down to refresh function but the spinner for pull down to refresh is not showing up when I call the [self.refreshControl beginRefreshing]

The above code is called inside the viewDidLoad cause the table is loading some data initially. The spinner works fine if I perform a pull down to refresh after the initial refresh. The title shows up but not the spinner.

Cant seem to solve this problem. It works fine on iOS 9.3.2 but not on iOS 10.

Here is the code I am using currently.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupView];
    [self customSetup];
    self.refreshControl = [[UIRefreshControl alloc] init];
    self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Updating Discounts..."];
    [self.refreshControl addTarget:self action:@selector(reloadDeals) forControlEvents:UIControlEventValueChanged];
    [self.refreshControl beginRefreshing];
    [self.tableView setContentOffset:CGPointMake(0, -self.refreshControl.frame.size.height) animated:YES];
}

Thanks for your help in advance


回答1:


before the code:

[refreshControl beginRefresh]

insert the code:

[refreshControl layoutIfNeeded]




回答2:


Delaying call to refresh in viewDidLoad worked for me:

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.refreshControl beginRefreshing];
});



回答3:


You need to call [self.view layoutIfNeeded] to fix it in iOS 10. For my case it was enough to put the call to viewDidLoad (I was using storyboard in that project). For other cases viewWillAppear fits better.

- (void)viewDidLoad
  {
   [super viewDidLoad];
   [self.view layoutIfNeeded];
   ...



回答4:


This is a known and reported bug in iOS 10.

Radar rdar://27468436

I'm not sure if there are any workarounds.




回答5:


Same as @jpros answer but in swift

if #available(iOS 10.0, *) {
    tableView.refreshControl = refreshControl
} else {
    tableView.addSubview(refreshControl)
}
refreshControl.layoutIfNeeded()
refreshControl.beginRefreshing()



回答6:


I was only able to fix this by calling, from viewDidLoad():

refreshControl.layoutIfNeeded()



回答7:


In iOS10, we should add the UIRefreshControl using setRefreshControl of UITableView or UICollectionView.

if([self.tableView respondsToSelector:@selector(setRefreshControl:)]) {
    [self.tableView setRefreshControl:self.refreshControl];
}
else {
    [self.tableView addSubview:self.refreshControl];
}
[self.refreshControl layoutIfNeeded];
[self.refreshControl beginRefreshing];



回答8:


If your refresh indicator is not showing try enabling Bounce Vertically in Interface Builder for table view or scroll view.



来源:https://stackoverflow.com/questions/39489263/ios-10-0-uirefreshcontrol-not-showing-indicator

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