2013-01-02 97 views
3

我做了一個UITableView,我從Web服務中從JSON獲取數據。我想我先得到前5個對象,並將它們加載到我的tableView中。這是正確的。如何在UItableview中加載footerview加載?

然後我想,每當用戶滾動到頁腳..the未來5個對象應該是牽強,它應該在的tableView顯示..

我困在這裏..can任何人給我任何想法如何繼續下一步?

我的tableview具有從不同類型的自定義類加載的所有自定義單元格?

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    if(section==[array count]-1) 
    { 
     UITableViewCell *cell = [self tableView:mtableview1 cellForRowAtIndexPath:myIP]; 
     frame = cell.contentView.frame; 
     footerView = [[UIView alloc] init]; 
     footerView.backgroundColor=[UIColor clearColor]; 
     self.activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease]; 
     self.activityIndicator.hidesWhenStopped=YES; 

     self.activityIndicator.center = CGPointMake(65,50); 
     [self.activityIndicator startAnimating]; 

     UILabel* loadingLabel = [[UILabel alloc]init]; 
     loadingLabel.font=[UIFont boldSystemFontOfSize:12.0f]; 
     loadingLabel.textAlignment = UITextAlignmentLeft; 
     loadingLabel.textColor = [UIColor colorWithRed:87.0/255.0 green:108.0/255.0 blue:137.0/255.0 alpha:1.0]; 
     loadingLabel.numberOfLines = 0; 
     [email protected]"Loading......."; 
     loadingLabel.frame=CGRectMake(95,35, 302,25); 

     loadingLabel.backgroundColor =[UIColor clearColor]; 
     loadingLabel.adjustsFontSizeToFitWidth = NO; 
     [footerView addSubview:self.activityIndicator]; 
     [footerView addSubview:loadingLabel]; 
     [self performSelector:@selector(loadending) withObject:nil afterDelay:1.0]; 
     [loadingLabel release]; 

     NSLog(@"%f",mtableview1.contentOffset.y); 
     mtableview1.tableFooterView=footerView; 

     return footerView; 
    } 
    return nil; 
} 

我一直這樣做,但它的位置一直不正確。這是我的大問題。

+0

:您需要像在底部儀式中加載更多? –

回答

4

您可以使用下面的概念。概念是當用戶拉表視圖,然後重新加載額外的數據,如拉刷新。

Code Sample : 
//MARK: -UIScrollViewDelegate 
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ 
    if (scrollView.contentOffset.y <= - 65.0f) { 
     // fetch extra data & reload table view 
    } 
} 
+0

+1給出正確的問題解決方案的實現方式:) –

0

使用UIScrollViewDelegate方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 

    } 

在scrollViewDidScroll方法可以檢查排索引

NSIndexPath *indexPath = [[self.myTable indexPathsForVisibleRows]objectAtIndex:1]; //in middle visible of row 
int visibleRowIndex = indexPath.row; 
0

可以增加數在表中查看呼叫你裝載方法,當你到達最後一行檢查是否有更多內容可以顯示或不顯示。如果你有MOre內容顯示然後增加行數。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

增加行可以滾動到你WANN顯示所需的行數後...

0

我已經實現這個請看這這裏是我的代碼

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 

    if(footerView == nil) 
    { 
     footerView = [[UIView alloc] init]; 
     CGRect screenBounds = [[UIScreen mainScreen] bounds]; 

     if (ObjApp.checkDevice == 1) 
     { 
      UIImage *image = [[UIImage imageNamed:@"LoadMoreBtn.png"] 
           stretchableImageWithLeftCapWidth:8 topCapHeight:8]; 

      btnLoadMore = [UIButton buttonWithType:UIButtonTypeCustom]; 
      [btnLoadMore setBackgroundImage:image forState:UIControlStateNormal]; 
      if(screenBounds.size.height == 568) 
      { 
       // iPhone 5 
       [btnLoadMore setFrame:CGRectMake(74, 13, 148, 34)]; 
      } 
      else 
      { 
       // iPohne 4 and Older iPhones 
       [btnLoadMore setFrame:CGRectMake(74, 13, 148, 34)]; 
      } 
     } 
     else if (ObjApp.checkDevice == 2) 
     { 
      UIImage *image = [[UIImage imageNamed:@"LoadMoreBtn_iPad.png"] 
           stretchableImageWithLeftCapWidth:8 topCapHeight:8]; 

      btnLoadMore = [UIButton buttonWithType:UIButtonTypeCustom]; 
      [btnLoadMore setBackgroundImage:image forState:UIControlStateNormal]; 
      [btnLoadMore setFrame:CGRectMake(220, 26, 296, 67)]; 
     } 
     [btnLoadMore.titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; 
     [btnLoadMore setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
     [btnLoadMore addTarget:self action:@selector(btnLoadmore_clicked:) 
     forControlEvents:UIControlEventTouchUpInside]; 
     [footerView addSubview:btnLoadMore]; 
    } 
    return footerView; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    if (ObjApp.checkDevice == 1) 
    { 
     return 47; 
    } 
    else 
    { 
     return 100; 
    } 
    return 0; 
} 

#pragma mark - Button Click Methods 
-(void)btnLoadmore_clicked:(id)sender 
{ 
    if(page > 0) 
    { 
     sendpage++; 
     if(sendpage<= page) 
     { 
     [self loading]; 
     NSString *urlString = [NSString stringWithFormat:@"data={\"name\":\"%@\",\"lat\":\"%f\",\"page\":\"%d\",\"long\":\"%f\"}",txtSearchFld.text,ObjApp.current_Latitude,sendpage,ObjApp.current_Longitude]; 
     [WebAPIRequest WS_Search:self :urlString]; 

     CGFloat height = tblSearchResult.contentSize.height - tblSearchResult.bounds.size.height; 
     [tblSearchResult setContentOffset:CGPointMake(0, height) animated:YES]; 
     } 
    } 
}