
[英]Using UIRefreshControl in UIViewController with UITableView
[英]Refresh UITableView using UIRefreshControl
我在UIRefreshControl
中插入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]}];
}
}
按照@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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.