表格的下拉刷新

APPDelegate.m

@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[[MyTableViewController alloc]init]];

    [self.window makeKeyAndVisible];

    return YES;

}



.M

#import "MyTableViewController.h"


-(NSMutableArray *)allDatas {

    if (_allDatas == nil) {

        _allDatas = [@[@"张三", @"李四", @"王五"] mutableCopy];

    }

    return _allDatas;

}


- (void)viewDidLoad {

    [super viewDidLoad];

    //1.创建UIRefreshContol控件实例

    UIRefreshControl *rc = [[UIRefreshControl alloc]init];

    //2.将控件实例赋值给表格控制器的refreshControl属性

    self.refreshControl = rc;

    //3.添加 valueChanged事件的监听

    [rc addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];

  

}


-(void)refresh:(UIRefreshControl*)sender {

    

    NSLog(@"加载数据");

    

    //模拟加载数据时间2秒钟

    //模拟从网上 下来了 一个数据 赵六

    NSString *zhaoliu = @"赵六";

    

    [self performSelector:@selector(refreshOver:) withObject:zhaoliu afterDelay:2];

    

}


-(void)refreshOver:(NSString *)str {

    //将数据添加到 数组中

    [self.allDatas addObject:str];

    //刷新 tableView

    [self.tableView reloadData];

    //停止刷新

    [self.refreshControl endRefreshing];

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

   

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {


    return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


    return self.allDatas.count;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"id"];

    if (cell == nil) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"id"];

    }

    

    cell.textLabel.text = self.allDatas[indexPath.row];

    

    return cell;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值