UITableView - 使用reloadRowsAtIndexPath
问题描述:
我有一个UITableView
声明委托方法。动态更新numberOfRows
& numberOfSections
。UITableView - 使用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]
这个被调用时似乎会崩溃。我将如何处理数据数组数的变化?
答
要重新加载泰伯维的特定细胞的方法是reloadRowsAtIndexPaths:没有reloadRowsAtIndexPath
[self.tableview reloadRowsAtIndexPaths:[self.tableview indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
然而,对于reloadRowsAtIndexPaths到正常工作的数据源必须是洽。由于索引路径已经加载。
如果仍然使用此方法,您将在单元格中获取arrayIndexOutofBound错误或重复值(取决于数据源中的增加或减少)。
答
你可以试试这个。
[tblMe beginUpdates];
[tblMe reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
[tblMe endUpdates];
希望这可以帮助!
答
//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.
可能有多个部分。该部分可以更新刷新数据 –
然后,您可以使用通过' - reloadSections:withRowAnimation:'涉及的部分的索引集... – Alladinian