Reputation: 508
I insert UIRefreshControl
in my tblView, when I pulldown my table view it's call method cellForRowAtIndex
but my array list has no element then why it has been called? code for UIRefreshControl
in viewDidLoad
Method :
refreshControl = [[UIRefreshControl alloc]init];
[self.tblView addSubview:refreshControl];
[refreshControl addTarget:self action:@selector(refreshTablee) forControlEvents:UIControlEventValueChanged];
code for refreshTablee is:
#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];
}
Table methods are:
#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]}];
}
}
Upvotes: -1
Views: 71
Reputation: 508
as per @dreamBegin suggestion I reload my table in refreshTablee method and its working. Thanks for reply@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];
}
Upvotes: 1