How do I “hide” a UIRefreshControl?

前端 未结 12 935
醉梦人生
醉梦人生 2020-12-15 16:16

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 viewDid

相关标签:
12条回答
  • 2020-12-15 17:05

    There’s a very simple solution you can try: [self.refreshControl removeFromSuperview];

    0 讨论(0)
  • 2020-12-15 17:09

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

    0 讨论(0)
  • 2020-12-15 17:10

    Try this:

    [self.refreshControl removeFromSuperview];
    self.refreshControl = nil;
    
    0 讨论(0)
  • 2020-12-15 17:16

    An old question, but I was looking for an answer and nothing worked exactly like I wanted.

    This is what worked for me:

    Swift 4

    func createRefreshControl() {
        refreshControl = UIRefreshControl()
        refreshControl?.addTarget(self, action: #selector(self.myTableRefreshFunction), for: UIControlEvents.valueChanged)
        refreshControl?.tintColor = UIColor.white
        refreshControl?.endRefreshing()
    }
    
    func removeRefreshControl() {
        refreshControl?.removeTarget(self, action: #selector(self.myTableRefreshFunction), for: UIControlEvents.valueChanged)
        refreshControl = nil
    }
    

    I call createRefreshControl() when I want the control created, and removeRefreshControl when I want it removed.

    I had to remove the same target I initially added to the refresh control, otherwise it would refresh one time before it was actually removed.

    0 讨论(0)
  • 2020-12-15 17:18

    To hide refresh control and avoid warning Just use

    Objective C

    [self.refreshControl removeFromSuperview];

    Swift

    self.refreshControl.removeFromSuperview()
    
    0 讨论(0)
  • 2020-12-15 17:18
    [refreshControl setTintColor:[UIColor clearColor]];
    

    also you can do something like this:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (scrollView.contentOffset.y < 0)
            scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
    }
    
    0 讨论(0)
提交回复
热议问题