-(void)viewDidLoad{[superviewDidLoad];// Do any additional setup after loading the view, typically from a nib.self.navigationItem.leftBarButtonItem=self.editButtonItem;// self.refreshControl = [[UIRefreshControl alloc] init]; // 如果你没有做步骤2,取消注释本行。[self.refreshControladdTarget:selfaction:@selector(insertNewObject:)forControlEvents:UIControlEventValueChanged];// 设置下拉刷新时执行的动作UIBarButtonItem*addButton=[[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:selfaction:@selector(addButtonAction:)];// 通过代码触发下拉刷新动作self.navigationItem.rightBarButtonItem=addButton;}-(void)didReceiveMemoryWarning{[superdidReceiveMemoryWarning];// Dispose of any resources that can be recreated.}// 下拉刷新动作-(void)addButtonAction:(id)sender{[self.refreshControlbeginRefreshing];// 触发刷新动作}-(void)insertNewObject:(id)sender{// 使用Timer来模拟一个耗时的操作[NSTimerscheduledTimerWithTimeInterval:2target:selfselector:@selector(doSomething)userInfo:nilrepeats:NO];}// 这是模板自动生成的插入新项目的代码,我们把它移入了一个新方法,并增加结束刷新的代码。-(void)doSomething{if(!_objects){_objects=[[NSMutableArrayalloc]init];}[_objectsinsertObject:[NSDatedate]atIndex:0];NSIndexPath*indexPath=[NSIndexPathindexPathForRow:0inSection:0];[self.tableViewinsertRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];[self.refreshControlendRefreshing];// 结束刷新}