一:iOS6.0及以后:
- 下拉刷新控件UIRefreshControl
- TableView属性:refreshControl
二:使用
- (void)colseTheTB
{
[self dismissViewControllerAnimated:YES completion:nil];
} - (void)viewDidLoad
{
[super viewDidLoad]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(colseTheTB)]; //数据源
self.dataArray = [[NSMutableArray alloc]initWithCapacity:];
for (int i = ; i < ; i ++) {
[_dataArray addObject:[NSString stringWithFormat:@"%d",i]];
} //适用于 iOS6 之后,系统自带的下拉刷新控件 UIRefreshControl
UIRefreshControl *osRefresh = [[UIRefreshControl alloc]init];
osRefresh.tintColor = [UIColor lightGrayColor];
osRefresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
[osRefresh addTarget:self action:@selector(doPullRefresh:) forControlEvents:UIControlEventValueChanged];
self.refreshControl = osRefresh; } - (void)doPullRefresh:(UIRefreshControl *)refresh
{
if (refresh.refreshing) {
refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"正在刷新"];
[self performSelector:@selector(handleTheRefresh) withObject:nil afterDelay:];
} else
{
refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"释放刷新"]; }
} - (void)handleTheRefresh
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm:ss a"];
NSString *lastUpdated = [NSString stringWithFormat:@"时间:%@", [formatter stringFromDate:[NSDate date]]];
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated] ; static int num = ;
num--;
[_dataArray insertObject:[NSString stringWithFormat:@"%d",num] atIndex:]; [self.refreshControl endRefreshing];
[self.tableView reloadData];
}
三:显示情况
- 在iOS6上显示情况,请参见 qq for iPhone版本 app
- 在iOS7 显示情况,是菊花动画,一片一片的铺满