Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIRefreshControl在集合视图中不工作_Ios_Objective C_Uicollectionview_Uirefreshcontrol - Fatal编程技术网

Ios UIRefreshControl在集合视图中不工作

Ios UIRefreshControl在集合视图中不工作,ios,objective-c,uicollectionview,uirefreshcontrol,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]; -(v

我已将
UIRefreshControl
添加到我的收藏视图中:

self.refreshControl=[[UIRefreshControl alloc]init];
[self.refreshControl addTarget:self action:@selector(refreshCV:)forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:self.refreshControl];
-(void)refreshCV:(UIRefreshControl*)刷新{
NSLog(@“刷新”);
[刷新结束刷新];
}

但它并不总是起作用。换言之,有时在下拉时,它不调用刷新功能。如何解决此问题?

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

#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];
    }

}
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];
}

如果未使用
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];
}

下面是UIRefreshControl的一个示例

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

下面是UIRefreshControl的一个示例

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

您添加了
refreshCV
作为刷新控制的目标函数,而实际上在下面有
refreshttv
。请检查以确保确实需要哪个函数。

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

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

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

您使用的是UITableViewController,还是只是普通UIViewController中的UITableView?如果是后者,请参阅检查此项,很抱歉,但什么是addRefreshControl方法?这是我第一次遇到这种情况。@Joshua just AddSubViews您使用的是UITableViewController,还是普通UIViewController中的UITableView?如果是后者,请参阅检查此项。对不起,addRefreshControl方法是什么?这是我第一次遇到这种情况。@Joshua在键入问题时错误地添加了子视图