UIRefreshControl and UITableView's backgroundVIew

前端 未结 4 1046
说谎
说谎 2021-02-01 03:39

I have a UITableViewController on which I set a backgroundView. This controller has a UIRefreshControl installed. The problem is that when I set a background view, the refresh c

4条回答
  •  佛祖请我去吃肉
    2021-02-01 03:58

    It seems that UITableViewController pushes its UIRefreshControl to back to the 0 index during reload (behind its "backgroundView"), regardless at what index you put it in the first place. This is what worked for me (iOS 9): Disable refreshing in IB. Create UIRefreshControl in code and add it to tableView after setting up backgroundView:

        let someView = UIView()
    
        self.tableView.backgroundView = someView
    
        let refreshControl = UIRefreshControl()
    
        refreshControl.addTarget(self, action: #selector(MyTableViewController.refresh(_:)), forControlEvents: .ValueChanged)
    
        self.tableView.insertSubview(refreshControl, atIndex: 1)
    

提交回复
热议问题