2014-10-29 92 views
1

我在我的應用程序中創建一個收件箱模塊。我想問一下,我想在Json的數據插入之後在UITableView中創建一個標籤程序。通過我們點擊並獲取更多數據?如何做到這一點?像在臉書的例子,我們點擊消息,並向下移動,我們點擊加載更多的消息?在加載更多的消息標籤我發送另一個電話加載更多的消息。從json加載數據後在表視圖上創建標籤

+0

你指的是一個tableview中的無限滾動? – avismara 2014-10-29 11:09:46

+0

是的..我從我的服務器獲得25條記錄..我想創建一個標籤獲得25條記錄後,加載更多的記錄。 – 2014-10-29 11:13:46

+0

maam只是從Web Service獲取數據,並重新計算numberofrowinindexpath中的計數,它將根據您擁有的記錄數來加載。 – sanjeet 2014-10-29 11:22:09

回答

1

好吧,你必須一起破解這一切。這是通常的做法得到「加載更多的數據」在你的UITableViewcell

方法所需

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return dataRows+1; 
} 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

    //after setting tableviewcell 

    if(indexPath.row==dataRows){ 

    [email protected]"Load More Rows"; 
    } 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if(indexPath.row==dataRows){ 
     //there you can write code to get next rows 
    } 
} 

確定這就是黑客將不得不開始。看看這個CODE

,這似乎是最重要的方法是

- (void)reloadTableView:(int)startingRow

0

爲此,您可以將其設置爲按鈕。如果在tableview中單擊該按鈕,則可以獲得更多數據,或者可以像十乘十數據一樣逐步獲取數據。

創建自定義單元格,並設置自定義的鈕釦電池也給名btnLoadMore

在頭文件

@interface myViewController : UIViewController { 
    int loadMoreTableInt; 
    int paginationInt; 
} 

在.m文件

- (void)viewDidLoad { 
     [super viewDidLoad]; 
     loadMoreTableInt = 0; 
     paginationInt = 1;  
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     customCell *cell=(customCell*)[tableView dequeueReusableCellWithIdentifier:@"Reuse"]; 

     NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil]; 

     if(cell == nil) { 

     cell=[nib objectAtIndex:0]; 

     } 

    if(loadMoreTableInt-1> indexPath.row) { 

     cell.labelName.text = [NSString stringWithFormat:@"%@",[modelRoot.arrayName objectAtIndex:indexPath.row]]; 


    } else { 

     if(cell == nil) { 
      cell=[nib objectAtIndex:1]; 
     } 

     [cell.btnLoadMore setTitle:[NSString stringWithFormat:@"Load More "] forState:UIControlStateNormal]; 

     cell.btnLoadMore.tag=indexPath.row; 

     cell.accessoryType=UITableViewCellAccessoryNone; 

     [cell.btnSeeMorebtnLoadMore addTarget:self action:@selector(loadmoreButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 
        cell.selectionStyle=UITableViewCellSelectionStyleNone; 

    } 

在loadmoreButtonAction給出任何類似的代碼這

-(void)loadmoreButtonAction:(id)sender { 

    @try { 
     UIButton *btn=(id)sender; 

     paginationInt=paginationInt+1; 
     [tableview reloadData]; 

     CGPoint point; 
     point.x=40; 
     point.y=btn.tag*53; 

     NSIndexPath *path = [tableview indexPathForRowAtPoint:point]; 
     [tableview scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:NO]; 

     }@catch (NSException *exception) { 

     } 
} 
+0

泰克斯我會檢查nd讓你知道:) – 2014-10-30 06:35:12