UIRefreshControl - beginRefreshing not working when UITableViewController is inside UINavigationController

后端 未结 15 842
梦如初夏
梦如初夏 2020-11-28 03:03

I\'ve setup a UIRefreshControl in my UITableViewController (which is inside a UINavigationController) and it works as expected (i.e. pull down fires the correct event). Howe

15条回答
  •  误落风尘
    2020-11-28 03:44

    None of the other answers worked for me. They would cause the spinner to show and spin, but the refresh action itself would never happen. This works:

    id target = self;
    SEL selector = @selector(example);
    // Assuming at some point prior to triggering the refresh, you call the following line:
    [self.refreshControl addTarget:target action:selector forControlEvents:UIControlEventValueChanged];
    
    // This line makes the spinner start spinning
    [self.refreshControl beginRefreshing];
    // This line makes the spinner visible by pushing the table view/collection view down
    [self.tableView setContentOffset:CGPointMake(0, -1.0f * self.refreshControl.frame.size.height) animated:YES];
    // This line is what actually triggers the refresh action/selector
    [self.refreshControl sendActionsForControlEvents:UIControlEventValueChanged];
    

    Note, this example uses a table view, but it could just as well have been a collection view.

提交回复
热议问题