实现tableview的下拉刷新

实现tableview的下拉刷新
 推荐第三方下拉刷新代码http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
 tableview滑动就会触发这个方法?
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
 {
 //当tableview下拉到最后一行的时候才触发
 if (indexPath.row == self.m_data.count - 1) {
 
 //定义一个UIView
UIView *footSpinnerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 60.0f)];

//顶一个有刷新图标的view
 UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(130.0f, 0.0f, 60.0f, 60.0f)];
activity.color = [UIColor redColor];
[activity startAnimating];//启动有刷新图标的view
 
 footSpinnerView.backgroundColor = [UIColor grayColor];
[footSpinnerView addSubview:activity];

 //设置footerview
 self.myTableView.tableFooterView = footSpinnerView;

 // self.myTableView.tableHeaderView = footSpinnerView;
 
 dispatch_queue_t queue = dispatch_queue_create("my queue", nil);
 
 //在后台线程添加数据
dispatch_async(queue, ^(void){

 [self.m_data addObject:@"1000"];
 [self.m_data addObject:@"1001"];
 [self.m_data addObject:@"1002"];
 [self.m_data addObject:@"1003"];
 [self.m_data addObject:@"1004"];
 
 });
 
 //添加完数据就重新加载数据
 dispatch_async(queue, ^(void) {
 
 sleep(2);
 dispatch_sync(dispatch_get_main_queue(), ^(void){
 
 [self.myTableView reloadData];
 });
 });
 
 // [self.myTableView reloadData];
 dispatch_release(queue);
 [footSpinnerView release];
 [activity release];
 }
 }

  

 

转载于:https://www.cnblogs.com/fshmjl/p/4870383.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值