2012-11-08 27 views
0

我有一個UITableView顯示數據列表。iPhone - 添加新的部分和行到UITableView

該列表將包含圖像,所以我使用延遲加載加載圖像。現在我不想一次加載整個列表。

加載應該是這樣的,首先它應該加載一些10條記錄,當我們滾動到tableview時,它應該自動加載下10條記錄。

爲此,我需要在滾動到底部時添加行。 tableview可能包含不同的部分。

那麼如何在滾動時在tableview的末尾添加新行和新節?

回答

1

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    if (indexPath.row == [yourArray count]-1) 
     { 
     //start fetching the next set of data in background asynchronously and when fetching is complete use delegate methods to reload or append your current UITableView , meanwhile start a activity indicator as footer to show loading 
     } 
    } 

這是有效的方法,如果嘗試在滾動到達底部,同步實施,它會使你的設備卡住

1

首先,你想要做的東西被稱爲延遲加載

意味着您的表格視圖將加載圖像或顯示用戶當前可見的單元格中的數據。所以看看this的鏈接。它提供了可能對您有幫助的示例代碼。

並插入行,你可以使用

(void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;