Header Displaced in TableView with UIRefreshControl

前端 未结 5 1064
暗喜
暗喜 2020-12-09 08:33

My UIRefreshController is doing something odd. When I pull-down refresh, the tableView headers are displaced.

If I pull-down it looks fine, but if I scroll down the

5条回答
  •  时光取名叫无心
    2020-12-09 08:46

    a quick fix to this is to go like this

    Objective-C

    //header
    @property UITableViewController *tableController;
    
    //.m (right at the beginning of viewDidLoad for example)
    self.tableController = [[UITableViewController alloc] init];
    [self addChildViewController:self.tableController];
    self.tableController.tableView = self.tableView;
    
    ...
    
    //then create the refresh control and assign it to the UITableViewController
    self.tableController.refreshControl = refreshControl;
    

    Swift 2.1

    //Create an instance of a UITableViewController. This will host your UITableView.
    private let tableController = UITableViewController()
    
    //Add tableController as a childViewController and set its tableView property to your UITableView.
    self.addChildViewController(self.tableController)
    self.tableController.tableView = self.tableView
    self.refreshControl.addTarget(self, action: "refreshData:", forControlEvents: .ValueChanged)
    self.tableController.refreshControl = self.refreshControl
    

    this helps if you have your table hooked up to an IBOutlet and have other things linked into the storyboard you dont feel like messing with.

提交回复
热议问题