Clearing TableView contents
11,574
Solution 1
For clearing a tableView
, you just remove all objects from the array that is populating your table and you reload the tableView after that.
[myArray removeAllObjects];
[self.tableView reloadData];
Solution 2
Set a bool tableIsEmpty and set the number of rows in the tableview to either 0 (table is empty) or the arrays count according to this BOOl in
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
Of cousre you have to set tableIsEmpty = YES, when the button is pressed and to NO again when theres data loaded. Then call
[self.tableView reloadData];
Not tested but should work shouldnt it?
Solution 3
You can just add one variable as flag before reloading the table.
makeEmpty = YES;
[tableview reloadData];
makeEmpty = NO;
Then in the tableview delegate method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(makeEmpty)
return 0;
}
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
Can any one help me by providing code for how to clear all the table view cell contents. The tableview when a button is pressed gets reloaded but does not get cleared
Thanks Rakesh