Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
Objective c 实现Pull刷新将UITableViewController中的单元格向下移动_Objective C_Uitableview_Addsubview_Uirefreshcontrol - Fatal编程技术网

Objective c 实现Pull刷新将UITableViewController中的单元格向下移动

Objective c 实现Pull刷新将UITableViewController中的单元格向下移动,objective-c,uitableview,addsubview,uirefreshcontrol,Objective C,Uitableview,Addsubview,Uirefreshcontrol,我在放置UITableViewController和同时拉入刷新时遇到问题 我已经实现了pull-to-refresh,在实现pull-to-refresh时,会对服务器进行API调用,并获取数据并显示在表视图列表中。问题是,在拉动刷新时,表会从其实际位置向下移动。 下面是我的代码和截图 viewDidLoad{ refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self actio

我在放置UITableViewController和同时拉入刷新时遇到问题

我已经实现了pull-to-refresh,在实现pull-to-refresh时,会对服务器进行API调用,并获取数据并显示在表视图列表中。问题是,在拉动刷新时,表会从其实际位置向下移动。 下面是我的代码和截图

viewDidLoad{

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

}

- (void)handleRefresh:(id)sender
{
    // do your refresh here...
    [self Data];//method to get data from server
    [refreshControl endRefreshing];

}


非常感谢您的帮助。

UITableViewController具有内置的刷新控件。您不希望将新视图作为子视图添加到tableview中。只需初始化
self.refreshControl

viewDidLoad {
  self.refreshControl = [[UIRefreshControl alloc] init];
  [self.refreshControl setTintColor:[UIColor lightGrayColor]];
  [self.refreshControl addTarget:self action:@selector(didRefresh:) forControlEvents:UIControlEventValueChanged];
}

- (void)didRefresh:(UIRefreshControl *)sender {
  [sender endRefreshing];
  [self Data];
}

谢谢,我应用了你的代码,但现在当我下拉时,表中没有指示器视图。在下拉列表中未调用didRefresh方法。请确保您没有重写子类中的refreshControl。self.refreshControl是在UITableViewController中实现的,因此您不需要在类中声明它。此工作但didRefresh方法在下拉时调用了两次,这并不能解决我的问题。请确保没有其他方法调用refresh方法,并且包括[sender EndRefresh]。在didRefresh中设置断点并检查发送方。如果您仍然有问题,请发布一些代码。我检查了我的代码是否使用以下方法:-(无效)ScrollViewDiEndDeclaring:(UIScrollView*)scrollView{float endScrolling=scrollView.contentOffset.y+scrollView.frame.size.height;if(endScrolling>=scrollView.contentSize.height){NSLog(@“Scroll End Called”);bottomRefresh=YES;[self-Data];}}其中[self-Data];我又打电话来了。