2015-05-19 34 views
0

我有一個UITableView聲明委託方法。動態更新numberOfRows & numberOfSectionsUITableView - 使用reloadRowsAtIndexPath

(NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section{} 

(NSInteger)numberOfSectionsInTableView: 

除了使用[tableView reloadData],我將需要使用reloadRowsAtIndexPath

但是,我得到了無效行數的崩潰。我如何處理dataSource更改?讓我說我有一個數10的數組,並且當我通過拉動來從UIRefreshControls重新加載UITableView時,以及來自服務器的數據。從10開始,如果陣列的數量下降到1,我將如何處理reloadRowsAtIndexPath

[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathForVisibleRows] withRowAnimation:UITableViewRowAnimationNone] 

這個被調用時似乎會崩潰。我將如何處理數據數組數的變化?

+0

可能有多個部分。該部分可以更新刷新數據 –

+0

然後,您可以使用通過' - reloadSections:withRowAnimation:'涉及的部分的索引集... – Alladinian

回答

1

要重新加載泰伯維的特定細胞的方法是reloadRowsAtIndexPaths:沒有reloadRowsAtIndexPath

[self.tableview reloadRowsAtIndexPaths:[self.tableview indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone]; 

然而,對於reloadRowsAtIndexPaths到正常工作的數據源必須是洽。由於索引路徑已經加載。

如果仍然使用此方法,您將在單元格中獲取arrayIndexOutofBound錯誤或重複值(取決於數據源中的增加或減少)。

0

你可以試試這個。

[tblMe beginUpdates]; 
[tblMe reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone]; 
[tblMe endUpdates]; 

希望這可以幫助!

1
//call begin and end updates while performing some hard core actions on tableview 
    [My_Table beginupdates]; 
    [My_Table reloadRowsAtIndexPaths:[My_Table indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone]; 
    [My_Table endupdates]; 
    hope it will helps you.