-6

I added a button on the uinavigationbar I want to use it to delete all the rows of uitablview

How can I do that?

[self.tableView reloadData]

is not working here

Praphin SP
  • 69
  • 1
  • 14

4 Answers4

3

On the button action event remove all the objects from itemArray then reload tableView data. Before this make sure that in tableView delegate numberOfRowInsection you are passing itemArray count like that:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return [itemArray count];
}

// button action//

-(IBAction)deleteTableViewData
{
     [itemArray removeAllObjects];
     [tableView reloadData];
}
2

First remove all objects from the datasource:

[dataArray removeAllObjects]

and then reload the UITableView

[self.tableView reloadData]
iCode
  • 1,456
  • 1
  • 15
  • 26
1

[array removeAllObjects];

Clear the data source and then reload the data

Sekhar
  • 341
  • 2
  • 13
1

You are using an array to populate the UITableView. Remove all the objects from there and reload your data.

Make sure your numberOfRowsInSection is returning the array count and not a static value. And then do this:

[dataSourceArray removeAllObjects];
[tableView reloadData];