I have a couple of NSMutableArrays
which i need to clear when refreshing the view. However, when I try to clear them with [array removeAllObjects];
my tableview crashes due to index beyond bounds error
. All i do with the refresh, is clear the arrays and call the same function as in viewDidLoad for filling the tableview. [tableView reloadData]
doesn't get called until the very last line of the method.
EDIT: It's highly likely that the issue is this: I use a pull to refresh external lib, and when you scroll up and release the table, it bounces back down and thus the UITableView tries to load the next cell, which it cant because the array is cleared, and it's still being loaded.
Answer: removeAllObjects from the arrays, immediately do a self.tableView reloadData and then continue with the rest.
problem might be due to numberOfRowsInSection
returning some count and your data source array is empty.
just call [array removeAllObjects]
and in numberOfRowsInSection
return [array count]
.
I hope it will resolve your issue. Best of Luck!!!
I delete cells from my table view in the following manner-
NSMutableArray* indexPathsToDelete = [[NSMutableArray alloc] init];
for(unsigned int i = 0; i < [self.array count]; i++)
{
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
[self.tableView beginUpdates];
[self.array removeAllObjects];
[self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView endUpdates];
[indexPathsToDelete release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With