//创建下拉刷新
UIRefreshControl * refresh=[[UIRefreshControl alloc] init];
[refresh addTarget:selfaction:@selector(refreshAction:) forControlEvents:UIControlEventValueChanged];
NSAttributedString * string=[[NSAttributedString alloc] initWithString:@"下拉可刷新"];
refresh.attributedTitle=string;
tvc=[[UITableViewController alloc] init];
[self presentViewController:tvc animated:YES completion:^{
}];
tvc.refreshControl=refresh;
------------------------------------------------------------
-(void)refreshAction:(UIRefreshControl *) sender
{
NSAttributedString * string=[[NSAttributedString alloc] initWithString:@"加载中..."];
tvc.refreshControl.attributedTitle=string;
[string release];
[tvc.refreshControl beginRefreshing];
[self performSelectorInBackground:@selector(requestData:) withObject:nil];
}
-(void) requestData:(id) sender
{
sleep(3);
//在主线程上执行一个函数
[self performSelectorOnMainThread:@selector(reloadUI)
withObject:nil
waitUntilDone:NO];
}
//重新加载tableview
-(void)reloadUI
{
NSAttributedString * string=[[[NSAttributedString alloc] initWithString:@"下拉可刷新"] autorelease];
tvc.refreshControl.attributedTitle=string;
[tvc.refreshControl endRefreshing];
[self.tableView reloadData];
}