2015-03-25 13 views
1

У меня есть UITableView. Когда я прокручиваю нижнюю часть, он загружает больше данных. Как добавить анимацию загрузки в нижний колонтитул таблицы, когда она прокручивается вниз?Добавить нижний колонтитул загрузки на UITableView

+0

просто добавить анимацию? – Raptor

+0

ya, как и загрузка больше, но в последнем ряду ячейки –

+0

сделать это footerview of tableview ... –

ответ

2

Вы можете использовать MNMBottomPullToRefreshManager файл для загрузки дополнительных данных. Во-первых, вы должны инициализировать его в viewDidLoad, как

pullToRefreshManager_ = [[MNMBottomPullToRefreshManager alloc] initWithPullToRefreshViewHeight:60.0f tableView:table withClient:self]; 


- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
[pullToRefreshManager_ tableViewScrolled]; 
} 


- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate 
{ 
[pullToRefreshManager_ tableViewReleased]; 
} 


- (void)bottomPullToRefreshTriggered:(MNMBottomPullToRefreshManager *)manager 
{ 
    //method to get more data 
    // [self CallWebServiceToLoadMorePAYMENTS]; 

} 
} 

После перезагрузки ваш tableView вызов:

[pullToRefreshManager_ tableViewReloadFinished]; 
+0

отличный ответ :) – Nirmalsinh

+0

Спасибо, это лучшее решение до сих пор. Спасибо: D –

2

Попробуйте

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
UIView *headerView = [[[UIView alloc] init]autorelease]; 

[headerView setBackgroundColor:[UIColor clearColor]]; 

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button addTarget:self 
     action:@selector(aMethod:) 
forControlEvents:UIControlEventTouchDown]; 
[button setTitle:@"Load More" forState:UIControlStateNormal]; 
button.frame = CGRectMake(10.0, 210.0, 160.0, 40.0); 


[headerView addSubview:button]; 


return headerView; 

} 
+3

Эй, время иметь современные коды. 'release' и' autorelease' больше не требуются в ARC. – Raptor

+0

У меня есть 2 ошибки, откуда появилась headerLabel? –

1

Используйте это:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if(array.count>1){ 
      if(indexPath.row == array.count-1){ 
       [self setupTableViewFooter]; 
      } 
    } 
} 


- (void)setupTableViewFooter 
{ 
    // set up label 
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height)]; 
    footerView.backgroundColor = [UIColor clearColor]; 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; 
    label.font = [UIFont fontWithName:Font_MuseoSans size:14]; 
    label.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
    label.textColor = [UIColor darkGrayColor]; 
    label.text = @"Loading"; 

    self.footerLabel = label; 
    CGSize labelSize = [self.footerLabel sizeThatFits:footerView.frame.size]; 
    [footerView addSubview:self.footerLabel]; 

    // set up activity indicator 
    UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    activityIndicatorView.hidesWhenStopped = YES; 
    activityIndicatorView.color = [UIColor blackColor]; 

    self.activityIndicator = activityIndicatorView; 
    [self.activityIndicator startAnimating]; 

    [footerView addSubview:self.activityIndicator]; 

    CGRect footerFrame = footerView.frame; 
    label.frame = CGRectMake((footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width)/2, (footerFrame.size.height-labelSize.height)/2 
          , (footerFrame.size.width-labelSize.width - 4 - activityIndicatorView.frame.size.width), labelSize.height); 
    self.activityIndicator.frame = CGRectMake(label.frame.origin.x + labelSize.width + 4, (footerFrame.size.height-activityIndicatorView.frame.size.height)/2 
               , activityIndicatorView.frame.size.width, activityIndicatorView.frame.size.height); 

    self.tableView.tableFooterView = footerView; 
} 
Смежные вопросы