How do I “hide” a UIRefreshControl?

2020-02-09 06:14发布

Occasionally my table view won't be connected to a service to refresh, and in that case, I don't want the UIRefreshControl to be present.

After I add it in viewDidLoad, I've tried hiding it under certain circumstances with setEnabled: and setHidden: but neither seems to work.

12条回答
迷人小祖宗
2楼-- · 2020-02-09 06:43

I solved this problem by calling "yourRefreshControl".endEditing() inside the refresh function.

查看更多
一夜七次
3楼-- · 2020-02-09 06:45

I solved it this way:

-(void)updateUIWithAuthState:(BOOL)isAuthenticated {
    self.loginButton.enabled = !isAuthenticated;
    self.loginButton.tintColor = isAuthenticated ? [UIColor clearColor] : nil;

    self.logoutButton.enabled = isAuthenticated;
    self.logoutButton.tintColor = isAuthenticated ? nil : [UIColor clearColor];

    self.tableView.userInteractionEnabled = isAuthenticated;
    self.data = nil;
    [self.tableView reloadData];
}
查看更多
4楼-- · 2020-02-09 06:47

The best to implement UIRefreshControl is below.

 -(void)addRefreshControll{
    self.refreshControl=[[UIRefreshControl alloc] init];
    self.refreshControl.tintColor=[UIColor colorWithRed:0 green:183.0/255.0 blue:213/255.0 alpha:1.0];
    self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"Loading history..."];
    [self.refreshControl addTarget:self action:@selector(loadMoreChatFromCoreData) forControlEvents:UIControlEventValueChanged];
    self.tableView.refreshControl = self.refreshControl;
}

When there is no more record to load then remove refreshControl by below line

self.tableView.refreshControl = nil;

I have implemented same working fine.

查看更多
我只想做你的唯一
5楼-- · 2020-02-09 06:51

I had bad experience when set tableView.refreshConrol = nil , because when I set it back to old refreshControl, it started animation only in a second, so it looked not good, so when I need to disable refreshControl I use:

tableView.refreshControl?.endRefreshing()
tableView.refreshControl?.alpha = 0

when I need it back I use:

tableView.refreshControl?.alpha = 1
// and if I need to show refreshing indicator immediately I write:
tableView.refreshControl?.beginRefreshing()

P.S. Setting isHidden, isEnabled, isUserInteractionEnabled didn't help

查看更多
beautiful°
6楼-- · 2020-02-09 06:54

You have several ways to do this. I think the best way is to do a check in the viewDidLoad method with:

if (condition){
 //attach refreshControl
}

if this isn't possible the best way is put this code where you want to hide the refresh (I think in viewWillAppear method in if condition)

//End refresh control
[self.refreshControl endRefreshing];
//Remove refresh control to superview
[self.refreshControl removeFromSuperview];
查看更多
你好瞎i
7楼-- · 2020-02-09 06:55

Try this:

[self.refreshControl removeFromSuperview];
self.refreshControl = nil;
查看更多
登录 后发表回答