UITTable Viewの底にあるFooterViewがアップデートを実現しました。

11482 ワード

転載元:http://carlme.blog.163.com/blog/static/183716327201272421728204/
 
@interface FooterViewTestViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{



//       ,       ,       

NSMutableArray *tableData;



//         

NSMutableArray *tableMoreData;



// NSUInteger dataNumber; // BOOL _loadingMore; UITableView *table; } @property (nonatomic, retain) UITableView *table; @property (nonatomic, retain) NSMutableArray *tableData; @property (nonatomic, retain) NSMutableArray *tableMoreData; // - (void) createTableFooter; // - (void) loadDataBegin; // - (void) loadDataing; // - (void) loadDataEnd; @end @implementation FooterViewTestViewController @synthesize table; @synthesize tableData; @synthesize tableMoreData; - (void)viewDidLoad { [super viewDidLoad];   table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];   table.delegate = self;   table.dataSource = self;   [self.view addSubview:table];   tableData = [[NSMutableArray alloc] initWithObjects: @"January",@"February",@"March",@"April",@"May",@"June", @"July",@"August",@"September",@"October",@"November",@"December",nil];   tableMoreData = [[NSMutableArray alloc] initWithObjects:@"BAIDU",@"GOOGLE",@"FACEBOOK",@"YAHOO",nil];
  [self createTableFooter]; }
#pragma mark - #pragma mark Table view data source // Customize the number of sections in the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [tableData count]; } // Customize the appearance of table view cells. - (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]; }   cell.textLabel.text = [tableData objectAtIndex:indexPath.row]; return cell; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { //   if(!_loadingMore && scrollView.contentOffset.y > ((scrollView.contentSize.height - scrollView.frame.size.height)))   {     [self loadDataBegin];   } } // - (void) loadDataBegin{ if (_loadingMore == NO) { _loadingMore = YES; UIActivityIndicatorView *tableFooterActivityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(75.0f, 10.0f, 20.0f, 20.0f)]; [tableFooterActivityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray]; [tableFooterActivityIndicator startAnimating]; [self.table.tableFooterView addSubview:tableFooterActivityIndicator];     [self loadDataing]; } } // - (void) loadDataing {   dataNumber = [tableData count];   for (int x = 0; x < [tableMoreData count]; x++)   {     [tableData addObject:[tableMoreData objectAtIndex:x]];   }   [[self table] reloadData];   [self loadDataEnd]; } // - (void) loadDataEnd{   _loadingMore = NO;   [self createTableFooter]; } // - (void) createTableFooter{ self.table.tableFooterView = nil; UIView *tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.table.bounds.size.width, 40.0f)]; UILabel *loadMoreText = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 116.0f, 40.0f)]; [loadMoreText setCenter:tableFooterView.center]; [loadMoreText setFont:[UIFont fontWithName:@"Helvetica Neue" size:14]]; [loadMoreText setText:@" "]; [tableFooterView addSubview:loadMoreText]; self.table.tableFooterView = tableFooterView; } @end