iOS开源项目:SVPullToRefresh

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];
    });
}

 

 
posted @ 2013-06-20 15:47  shangdahao  阅读(6210)  评论(1编辑  收藏  举报