随着下拉刷新模式的影响力越来越大,苹果已经在ios 6 API中推出了下拉刷新控件,该类为:UIRefreshControl。
由于比较简单,故没有新建UITableViewController子类,代码实现如下:
- (void)clickBtn:(UIButton *)sender
{
tabViewCtl = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
tabViewCtl.tableView.backgroundColor = [UIColor grayColor];
[self presentViewController:tabViewCtl animated:YES completion:nil];
[tabViewCtl release];
UIRefreshControl *refCtl = [[UIRefreshControl alloc] init];
refCtl.attributedTitle = [[[NSAttributedString alloc] initWithString:@"下拉刷新"] autorelease];
[refCtl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];
tabViewCtl.refreshControl = refCtl;
[refCtl release];
}
- (void)refreshStart
{
if (tabViewCtl.refreshControl.refreshing)
{
tabViewCtl.refreshControl.attributedTitle = [[[NSAttributedString alloc] initWithString:@"加载中..."] autorelease];
NSLog(@"刷新中...");
NSString *str = @"刷新完成!";
[self performSelector:@selector(refreshOver:) withObject:str afterDelay:3];
}
}
- (void)refreshOver:(id)obj
{
[tabViewCtl.refreshControl endRefreshing];
tabViewCtl.refreshControl.attributedTitle = [[[NSAttributedString alloc] initWithString:@"下拉刷新"] autorelease];
NSLog(@"%@",obj);
}