UIRefreshControl无法在集合视图中工作

时间:2016-04-13 09:06:12

标签: ios objective-c uicollectionview uirefreshcontrol

我在我的收藏视图中添加了UIRefreshControl

 self.refreshControl = [[UIRefreshControl alloc]init];
[self.refreshControl addTarget:self action:@selector(refreshCV:) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:self.refreshControl]; 

- (void)refreshCV:(UIRefreshControl *)refresh{ 
      NSLog(@"Refresh");
      [refresh endRefreshing];
}

但它总是不起作用。换句话说,有时在下拉时它不会调用刷新功能。怎么解决这个问题?

5 个答案:

答案 0 :(得分:2)

试试这个answer。 您必须设置集合视图的alwaysBounceVertical属性。

答案 1 :(得分:0)

#pragma mark UIRefreshControl

- (void) setUpRefreshControl {
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];

    //add UIRefreshControl to Collection view
    [self.collectionView addSubview:refreshControl];
}

- (void)refresh:(id)sender 
{
    UIRefreshControl *refreshControl = (UIRefreshControl *)sender;

    // End the refreshing
    if (refreshControl) {
        [refreshControl endRefreshing];
    }

}

答案 2 :(得分:0)

如果您没有使用UITableViewController课程,请执行以下操作

UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = self.myTableView;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshTV:) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = self.refreshControl;

- (void)refreshTV:(UIRefreshControl *)refresh{ 
      NSLog(@"Refresh");
      [refresh endRefreshing];
}

答案 3 :(得分:0)

以下是UIRefreshControl的示例。

UIRefreshControl *control = [[UIRefreshControl alloc] initWithFrame:CGRectZero];
control.tintColor = someColor;
[control sizeToFit];
[tableView addSubview:control];

答案 4 :(得分:0)

您添加refreshCV作为刷新控制的目标函数,而实际上下面有refreshTV。请检查以确定您确实需要哪种功能。