• EGORefreshTableHeaderView下拉刷新


    - (void)viewDidLoad {
        [super viewDidLoad];
    	
    	if (_refreshHeaderView == nil) {
    		
    		EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
    		view.delegate = self;
    		[self.tableView addSubview:view];
    		_refreshHeaderView = view;
    		[view release];
    		
    	}
    	
    	//  update the last update date
    	[_refreshHeaderView refreshLastUpdatedDate];
    
    	
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    	return YES;
    }
    
    
    #pragma mark -
    #pragma mark UITableViewDataSource
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 10;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 4;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
        
    	// Configure the cell.
    
        return cell;
    }
    
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    	
    	return [NSString stringWithFormat:@"Section %i", section];
    	
    }
    
    
    #pragma mark -
    #pragma mark Data Source Loading / Reloading Methods
    
    - (void)reloadTableViewDataSource{
    	
    	//  should be calling your tableviews data source model to reload
    	//  put here just for demo
        NSLog(@"reloadTableViewDataSource");
    	_reloading = YES;
    	
    }
    
    - (void)doneLoadingTableViewData{
    	
    	//  model should call this when its done loading
    	_reloading = NO;
        NSLog(@"doneLoadingTableViewData");
    //    结束当前刷新
    	[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
    	
    }
    
    
    #pragma mark -
    #pragma mark UIScrollViewDelegate Methods
    //上滑下滑都会调用当前的scrollview 所以必须判断是否需要刷新
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{	
    	
         NSLog(@"scrollViewDidScroll");
    	[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
       
    		
    }
    
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    	
        NSLog(@"scrollViewDidEndDragging");
    	[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
        
    	
    }
    
    
    #pragma mark -
    #pragma mark EGORefreshTableHeaderDelegate Methods
    //下拉结束上滑的时候调用此函数
    - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    	NSLog(@"egoRefreshTableHeaderDidTriggerRefresh");
        //在这里改变_reloading 不然会一直调用此过程
    	[self reloadTableViewDataSource];
        //调用doneLoadingTableViewData ,在这个函数里再改变_reloading,让其可以重新实现下拉刷新
    	[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    	
    }
    //当返回no的时候就会刷新数据 当拖拽的时候就会调用此函数,当返回yes的时候egoRefreshTableHeaderDidTriggerRefresh就不会被调用
    
    - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    	NSLog(@"egoRefreshTableHeaderDataSourceIsLoading");
    	return _reloading; // should return if data source model is reloading
    	
    }
    
    - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    	NSLog(@"egoRefreshTableHeaderDataSourceLastUpdated");
    	return [NSDate date]; // should return date data source was last changed
    	
    }
    
    
    #pragma mark -
    #pragma mark Memory Management
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
    }
    
    - (void)viewDidUnload {
    	_refreshHeaderView=nil;
    }
    
    - (void)dealloc {
    	
    	_refreshHeaderView = nil;
        [super dealloc];
    }
    

      

  • 相关阅读:
    诸葛马前课andoid app 应用
    C#读写文件总结
    C#写的较完美验证码通用类
    利用C#转换图片格式及转换为ico
    集合>哈希表类Hashtable和SortedList排序列表类
    C# 4.0 新特性dynamic、可选参数、命名参数等
    String.Format格式说明
    C# 4动态编程新特性与DLR剖析
    C#中const和readonly的区别
    2014年7月阅读链接
  • 原文地址:https://www.cnblogs.com/AbelChen1991/p/3675609.html
Copyright © 2020-2023  润新知