2011-05-28 60 views
12

嘿, 任何人都可以指導我通過這個我有大約15個表中的條目我想另一個15在上一個UITableViewCell中獲得更多的負載。任何人都可以幫我嗎?在uitableviewcell中做一個「加載更多」按鈕?

+2

[「Load More」in UITableView](http://stackoverflow.com/questions/4410257/)或[如何實現「Load 25 More」](http://stackoverflow.com/questions/) 2801069 /)或[郵件應用程序加載更多的消息](http://stackoverflow.com/questions/4396464/)或[在iPhone中加載更多記錄](http://stackoverflow.com/questions/4965919/)或[Add加載更多選項到表[視圖](http://stackoverflow.com/questions/5898399/)其中[others](http://stackoverflow.com/search?q=iphone+load+more) – 2011-05-28 07:32:41

回答

19

顯示額外的行中的tableview,在

- (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 
    } 
} 

您需要根據顯示的行更新numberOfRows變量。

編輯:獲取額外的條目後,您可以使用以下方法將它們添加到現有的條目數組中。您的原始數組應該是NSMutableArray以使用此方法。

[originalEntriesArray addObjectsFromArray:extraEntriesArray];

+0

@SriPriya,添加此line'numberOfRows = [yourEntriesArray count] + 1;'使之更加清晰。 – EmptyStack 2011-05-28 05:48:28

+0

@Simon:你好,我更新了代碼 – SriPriya 2011-05-28 05:53:23

+0

@SriPriya,嗯:) – EmptyStack 2011-05-28 05:56:32

1

希望這有助於

我花了一個可變數組和一個整型變量,並設置數組整型變量

 
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil]; 
dataRows = [arr count]; 

,然後我設定數量的總數根據表格的數據源方法中的整數變量在行中的行數

 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return dataRows+1; 
} 

因爲你想在最後一個額外的單元格。

現在就設置表單元的

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

{ 靜態的NSString * CellIdentifier = @ 「小區」 的文本;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell... 

//setting the text of the cell as per Mutable array 
if (indexPath.row < [arr count]) { 

    cell.textLabel.text = [arr objectAtIndex:indexPath.row]; 
} 

//setting the text of the extra cell 

if (indexPath.row == dataRows) { 
    cell.textLabel.text = @"more cells"; 
}  
return cell; 

}

現在

的多個細胞的細胞的命中你想要額外的細胞右所以只需添加

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

方法裏面的代碼,意味着你必須做這樣的事情

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row == dataRows) 
    { 
     //code for exra cells please 
    } 
} 

運行您的應用程序來檢查此代碼。

4

下載它,我寫的東西可能會有所幫助:https://github.com/nmondollot/NMPaginator

它封裝了分頁,並與幾乎使用頁面和per_page參數的任何web服務工作。它還具有一個UITableView,可在您向下滾動時自動獲取下一個結果。