我在我的tblView中插入了UIRefreshControl,当我下拉我的表视图时,它是调用方法cellForRowAtIndex,但是我的数组列表没有元素,那么为什么要调用它呢?viewDidLoad方法中的UIRefreshControl代码:
refreshControl = [[UIRefreshControl alloc]init];
[self.tblView addSubview:refreshControl];
[refreshControl addTarget:self action:@selector(refreshTablee) forControlEvents:UIControlEventValueChanged];refreshTablee的代码是:
#pragma mark:refresh table
- (void)refreshTablee {
//TODO: refresh your data
[refreshControl endRefreshing];
page=1;
slot = 10;
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:true];
[apiObj getAskQuestion:@{@"user_id":usr.usrid,@"owner_id":usr.owner_id ,@"page":[NSString stringWithFormat:@"%d",page]}];
[backupArr removeAllObjects];
[questionList removeAllObjects];
}表的方法有:
#pragma mark:table view delegate datasource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return questionList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//code for returning cell
return cell;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ((int)indexPath.row == (slot-2)) {
page = page+1;
slot = slot+10;
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:true];
[apiObj getAskQuestion:@{@"user_id":usr.usrid,@"owner_id":usr.owner_id ,@"page":[NSString stringWithFormat:@"%d",page]}];
}
}发布于 2018-06-15 19:19:00
根据@dreamBegin的建议,我用refreshTablee方法重新加载了我的表,并且它是工作的。感谢回复@dreamBegin
#pragma mark:refresh table
- (void)refreshTablee {
//TODO: refresh your data
[refreshControl endRefreshing];
page=1;
slot = 10;
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:true];
[apiObj getAskQuestion:@{@"user_id":usr.usrid,@"owner_id":usr.owner_id ,@"page":[NSString stringWithFormat:@"%d",page]}];
[backupArr removeAllObjects];
[questionList removeAllObjects];
[self.tblView reloadData];
}https://stackoverflow.com/questions/50874325
复制相似问题