2016-11-11 65 views

回答

0

我在執行相同的功能目標-C

cellForRowAtIndexPath

if (indexPath.row == [self.yourArrayData count] - 1) 
{ 
    // Call the API 
    [self loadMoreData:@"all" andPages:[NSString stringWithFormat:@"%ld", (long)pages] AndIsLoadMore:YES]; 
} 

添加裝載機或設計

-(void)addLoaderViewAtBottom { 
    viewLoader = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.frame.size.width, 50)]; 
    [viewLoader setBackgroundColor:[UIColor whiteColor]]; 
    [self.view addSubview:viewLoader]; 

    UIActivityIndicatorView *activityIndicator1 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    activityIndicator1.center = CGPointMake((SCREEN_SIZE.width/2), 30); 
    activityIndicator1.alpha = 1.0; 
    activityIndicator1.hidden = NO; 
    [viewLoader addSubview:activityIndicator1]; 

    [activityIndicator1 startAnimating]; 

} 

-(void)hideLoaderView { 
[UIView animateWithDuration:1 
       animations:^(void) { 
        [viewLoader setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 50)]; 

       }]; 
} 

然後使用此兩種方法你的API調用方法。呼叫addLoaderViewAtBottom API調用啓動時並得到響應

快樂編碼後打電話hideLoaderView ...

0

初始化UIActivityIndicatorView

@interface MyBulletinVC() 
{ 
    UIActivityIndicatorView *activityLoadMore; 
} 

-(void)viewDidLoad 
{ 
    activityLoadMore = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)]; 
} 

檢查時UITableView被滾動,什麼是content offset

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
{ 
    float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height; 
    float tblBottomEdge = _tblBulletin.frame.size.height+_tblBulletin.frame.origin.y; 

    if (bottomEdge <= tblBottomEdge) 
    { 
     return; 
    } 

    if (bottomEdge >= scrollView.contentSize.height) 
    { 
     [self show_bottom_loader]; 
    } 
} 

如果根據content offset適用,則顯示裝載機在表的頁腳:數據加載時

-(void)show_bottom_loader 
{ 
    _tblBulletin.tableFooterView = [self returnLoaderViewWhileFetchingRecords]; 
    CGPoint newContentOffset = CGPointMake(0, [_tblBulletin contentSize].height - _tblBulletin.bounds.size.height); 
    [_tblBulletin setContentOffset:newContentOffset animated:YES]; 
    [self getNewsRecords]; 
} 

隱藏頁腳:

-(void)hide_bottom_loader 
{ 
_tblBulletin.tableFooterView = nil; 
UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; 
v.backgroundColor = [UIColor clearColor]; 
[_tblBulletin setTableFooterView:v]; 
[activityLoadMore stopAnimating]; 
} 

-(UIView*)returnLoaderViewWhileFetchingRecords 
{ 
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0,_tblBulletin.frame.size.width,44)]; 
    view.backgroundColor =[UIColor clearColor]; 

    UILabel *lblBg =[[UILabel alloc]initWithFrame:CGRectMake(0,1,_tblBulletin.frame.size.width,42)]; 
    lblBg.backgroundColor =[UIColor whiteColor]; 
    [view addSubview:lblBg]; 

    UILabel *lbl =[[UILabel alloc]initWithFrame:CGRectMake(_tblBulletin.frame.size.width/2 - 20,0,_tblBulletin.frame.size.width/2,view.frame.size.height)]; 
    lbl.textAlignment = NSTextAlignmentLeft; 
    lbl.text = @"Loading..."; 
    lbl.font = [UIFont fontWithName:@"Arial" size:14.0f]; 
    lbl.textColor = [UIColor darkGrayColor]; 
    lbl.backgroundColor = [UIColor clearColor]; 
    lbl.userInteractionEnabled = NO; 
    [view lbl]; 

    activityLoadMore.frame = CGRectMake(_tblBulletin.frame.size.width/2-35,22,0,0); 
    [activityLoadMore startAnimating]; 
    [view addSubview:activityLoadMore]; 

    return view; 
} 

-(void)getNewsRecords 
{ 
    //fetch new records and add to your array. 
    [self hide_bottom_loader]; 
    //reload table. 
} 

替換tblBulletin與你的表名。

相關問題