Alex Rivera | Logout

UITableView delete all rows at once

Asked 2011-06-10T21:56:44.977
20

How is it possible to delete all rows from UITableView at once? Because when I reload table view with new data, I am still inserting new rows:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    CustomTableViewCell *cell = (CustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[CustomTableViewCell alloc] initWithFrame:CGRectZero] autorelease];
    }

    //... setting the new cell here ...

    return cell;
}

Thank you.

Edit
Report

2 Answers

49

Do this.

Before you are reloading the table with

[tableView reloadData];

Remove all objects from your tableView array (The array which populated your tableView) For example.

[myArray removeAllObjects];
[tableView reloadData];
answered 2011-06-10T22:27:20.073
4

Delete all of your dataSource, then call reloadData.

answered 2011-06-11T01:36:35.893

Your Answer