간단 실현---위로 당기기 로딩 리셋---

ROOTViewController는 보기 컨트롤러로 직접 설정됩니다.APPdelegate의 코드를 나는 붙이지 않겠다.일시.h의 파일
코드 주석은 이미 매우 명확한데, 그 중에서 말하는 국화는 동적 리셋도이다.
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
    //    
    NSMutableArray *tableData;
    //            
    NSMutableArray *tableMoreData;
    //    
    NSUInteger dataNumber;
    //    
    BOOL _loadingMore;
}
@property(nonatomic,retain)UITableView *table;

//         ,       
- (void) createTableFooter;
//      
- (void) loadDataBegin;
- (void) loadDataing;
- (void) loadDataEnd;
@end

다음은.m의 파일
#import "RootViewController.h"

@interface RootViewController ()

@end


@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.view.backgroundColor = [UIColor orangeColor];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 320, 460) style:UITableViewStylePlain];
    self.table.backgroundColor = [UIColor orangeColor];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    tableData = [[NSMutableArray alloc] initWithObjects:
                 @"1111",@"2222",@"3333",@"4444",@"5555",@"5555",@"5555",@"5555",@"5555",@"5555",@"5555",nil];
    tableMoreData = [[NSMutableArray alloc] initWithObjects:@"  1",@"  2",@"  3",@"  4",nil];
    
    [self createTableFooter];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tableData count];
}


- (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];
    }
    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    return cell;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    //         80        ,     ,      0;
    if (!_loadingMore && scrollView.contentOffset.y > (scrollView.contentSize.height-scrollView.frame.size.height +80)) {
        [self loadDataBegin];
    }
    
}

- (void)loadDataBegin
{
    
    //if (_loadingMore == NO) {
        _loadingMore = YES;
       
        [self loadDataing];
   // }
}

//               
- (void) loadDataing
{
    dataNumber = [tableData count];
    for (int x = 0; x < [tableMoreData count]; x++) {
        [tableData addObject:[tableMoreData objectAtIndex:x]];
    }
    [self.table reloadData];
    [self createTableFooter];
    [self loadDataEnd];
}

- (void) loadDataEnd
{
    _loadingMore = NO;
}
- (void)createTableFooter
{
    UIView *tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.table.bounds.size.width, 30)];
    //             
    UILabel *loadMoreText = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 116, 40)];
    [loadMoreText setCenter:tableFooterView.center];
    [loadMoreText setFont:[UIFont fontWithName:@"Helvetica Neue" size:14]];
    [loadMoreText setText:@"      "];
    [tableFooterView addSubview:loadMoreText];
    self.table.tableFooterView = tableFooterView;
    
    //       
    UIActivityIndicatorView *tableFootActivityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(75, 10, 20, 20)];
    [tableFootActivityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [tableFootActivityIndicatorView startAnimating];
    [self.table.tableFooterView addSubview:tableFootActivityIndicatorView];
    
}


- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

@end

좋은 웹페이지 즐겨찾기