2014-04-26 46 views
0

當用戶到達當前加載內容的末尾時,很難弄清楚如何向我的tableview添加其他部分。我的表是每件內容givien在tableview中的一段這樣的方式設置,我不知道如何去使用這樣的庫添加說50個新的部分到我的表:IOS在加載時插入多個部分更多

https://github.com/samvermette/SVPullToRefresh

- (void)insertRowAtBottom { 
    __weak SVViewController *weakSelf = self; 

    int64_t delayInSeconds = 2.0; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     [weakSelf.tableView beginUpdates]; 
     [weakSelf.dataSource addObject:[weakSelf.dataSource.lastObject dateByAddingTimeInterval:-90]]; 
     [weakSelf.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:weakSelf.dataSource.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationTop]; 
     [weakSelf.tableView endUpdates]; 

     [weakSelf.tableView.infiniteScrollingView stopAnimating]; 
    }); 
} 

回答

1

我第一次做了我的數組Mutable,以便我可以添加對象。然後,你也必須重新加載tableview,因爲你正在改變myArray.count的數量我擡頭看看NSIndexSet是什麼,我爲我的數組做了一個,所以我可以爲我的tableview設置新的部分(在底部或頂部添加),這是我使用的全部「代碼塊」。

//Reload the tableview and update the array count 
[self.tableView reloadData]; 
//Start the update 
      [weakSelf.tableView beginUpdates]; 
//Created the NSIndexSet to go into the next method 
      NSIndexSet *indexSet = [self.games indexesOfObjectsPassingTest:^(id obj, NSUInteger idx, BOOL *stop){ 
       return [obj isKindOfClass:[NSString class]]; 
      }]; 
//Inserting the new sections 
      [weakSelf.tableView insertSections:indexSet withRowAnimation:UITableViewRowAnimationTop]; 
      [weakSelf.tableView endUpdates]; 
      //Stop the Animation 
      [weakSelf.tableView.pullToRefreshView stopAnimating]; 

如果不重新加載的tableview你的tableview 不會更新。它甚至可能會因爲出現一些奇怪的錯誤而崩潰。

+0

這對我有很大的幫助。感謝您的出色答案! – Tander

相關問題