SVPullToRefresh也是一個下拉刷新的項目:https://github.com/samvermette/SVPullToRefresh
SVPullToRefresh 允許你通過一行代碼把下拉刷新添加至UIScrollView子類別,不需要依賴委托或者子類化UITableViewController。另外,該項目支持簡單自定義文本、箭頭的外觀。
這些UIScrollView類別讓下拉刷新和UIScrollView的無限滾動變得非常簡單。
- (void)viewDidLoad { [super viewDidLoad]; [self setupDataSource]; __weak SVViewController *weakSelf = self; // setup pull-to-refresh [self.tableView addPullToRefreshWithActionHandler:^{ [weakSelf insertRowAtTop]; }]; }
- (void)insertRowAtTop { __weak SVViewController *weakSelf = self; int64_t delayInSeconds = 2.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [weakSelf.tableView beginUpdates]; [weakSelf.dataSource insertObject:[NSDate date] atIndex:0]; [weakSelf.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom]; [weakSelf.tableView endUpdates]; [weakSelf.tableView.pullToRefreshView stopAnimating]; }); }