UIRefreshControl 下拉刷新

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //UIRefreshControl
    //系统自带,继承自UIControl,UIControl继承自UIView
    UIRefreshControl * refresh = [[UIRefreshControl alloc] init];
    [self.tableView addSubview:refresh];
    
    //设置标题
    NSAttributedString * title = [[NSAttributedString alloc] initWithString:@"下拉刷新"];
    refresh.attributedTitle = title;
    
    //监听什么时候开始下拉刷新
    [refresh addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];


}


//监听方法
- (void)refresh:(UIRefreshControl *)refresh
{
    NSLog(@"开始刷新");
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
       
        [NSThread sleepForTimeInterval:2];
        //回主线程刷新
         dispatch_sync(dispatch_get_main_queue(), ^{
             
             [refresh endRefreshing];
         });
    });
}