ios下拉刷新

ios下拉刷新

//
//  ViewController.m
//  tabview
//
//  Created by Young on 15/10/21.
//  Copyright © 2015年 Young. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property int count;
@property UIRefreshControl*myref;
 @end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _count=5;
    
    
    _myref = [[UIRefreshControl alloc] init];
    _myref.attributedTitle=[[NSAttributedString alloc]initWithString:@"下拉刷新、、、" ];
    [_myref addTarget:self action:@selector(refreshControl) forControlEvents:UIControlEventValueChanged];
    [self setRefreshControl:_myref];

}

-(void)refreshControl{
     //延时3秒
    [self performSelector:@selector(download) withObject:nil afterDelay:3];

}

-(void)download{

    _count++;
    
    // 刷新表格
    [self.tableView reloadData];
    
    // 完成刷新
    [self.myref endRefreshing];
//    self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];}


}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  
    return _count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    static NSString* sid=@"sid";
    
    UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:sid];
  
    
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sid];
    }
    cell.textLabel.text=[NSString stringWithFormat:@"%d  %@",indexPath.row,[NSDate date]];
 
    return cell;

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

ios下拉刷新_第1张图片

你可能感兴趣的:(ios)