ios6新特性之下拉刷新UIRefreshControl

ios6官方提供了下拉刷新的功能,水滴状,下面是它的一些用法

1.用UITableViewController

#import <UIKit/UIKit.h>


@interface RefreshViewController : UITableViewController


@end


- (void)viewDidLoad

{

    [super viewDidLoad];

    

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

    refreshControl.tintColor = [UIColor blackColor];

    refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"刷新"];

    [refreshControl addTarget:self action:@selector(refreshView:) forControlEvents:UIControlEventValueChanged];

    self.refreshControl = refreshControl;

}


- (void)refreshView:(UIRefreshControl*)refreshControl

{

   if (refreshControl.refreshing)

   {

       refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"refreshing..."];

       [self performSelector:@selector(loadData)];

   }

}


- (void)loadData

{

    //load data

    [self.refreshControl endRefreshing];

    [self.tableView reloadData];

}


2.UIRefreshView + UITableView

@interface DefaultTableView : UITableView


@end


- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

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

        refreshView.attributedTitle = [[NSAttributedString alloc] initWithString:@"下拉刷新"];

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

        [self addSubview:refreshView];

    }

    return self;

}


- (void)refreshView:(UIRefreshControl*)refreshView

{

    if (refreshView.refreshing)

    {

        refreshView.attributedTitle = [[NSAttributedString alloc] initWithString:@"loading..."];

        [self performSelector:@selector(loadDataForTableView:) withObject:refreshView];

    }

}


- (void)loadDataForTableView:(UIRefreshControl*)refreshView

{

     //load data

}


你可能感兴趣的:(ios6新特性之下拉刷新UIRefreshControl)