UIRefreshControl is in wrong position in UITableViewController

前端 未结 3 1708
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 14:58

I\'ve seen quite a few problems with UIRefreshControl, and I\'m having a problem as well with my UITableViewController. The problem occurs so randomly and henceforth I cannot fi

相关标签:
3条回答
  • 2021-02-13 15:37

    I had the same problem and fixed it with this:

    override func viewDidLoad() {
        let refreshControl = UIRefreshControl()
        refreshControl.addTarget(self, action: "refresh:", forControlEvents: .ValueChanged)
        tableView.backgroundView = refreshControl // <- THIS!!!
    }
    

    Instead of adding a subview assign the refreshControl as backgroundView

    0 讨论(0)
  • 2021-02-13 15:41

    override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() refreshControl?.superview?.sendSubview(toBack: refreshControl!) }

    0 讨论(0)
  • 2021-02-13 15:45

    This is a known bug with iOS7; sometimes the refresh control is put incorrectly in the front of the view hierarchy instead of back. You can counter part of the problem by sending it to back after layout:

    - (void)viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];
    
        [self.refreshControl.superview sendSubviewToBack:self.refreshControl];
    }
    

    Animation will still be imperfect, but at least it will still be below the table view. Please open a bug report with Apple for this issue.

    Also, as stated in another answer, you should not add the refresh control to the view hierarchy yourself. The table view controller will do that for you. But that is not the issue here.

    Swift version

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        refreshControl?.superview?.sendSubview(toBack: refreshControl!)
    }
    
    0 讨论(0)
提交回复
热议问题