Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clear all the rows of uitableview

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

How can I do that?

like image 567
Ali Avatar asked Mar 13 '11 17:03

Ali


People also ask

How do I delete extra cells in UITableView?

So, to remove a cell from a table view you first remove it from your data source, then you call deleteRows(at:) on your table view, providing it with an array of index paths that should be zapped. You can create index paths yourself, you just need a section and row number.

How do you delete a row in Swift?

When a user slides horizontally across a row the editing style of the Tabel View Cell is set to delete. When the delete button is pressed, the item is deleted in the array and also the row is deleted in the Table View. Build and run the project and swipe-to-delete a row from the Table View.

How do you customize swipe edit buttons in UITableView?

As of iOS 8.0 there's an easy way to customize the list of buttons that appear when the user swipes from right to left: editActionsForRowAt . Return an array of UITableViewRowAction objects that have titles and styles (and also background colors if you want to customize their appearance), and iOS does the rest.

What is IndexPath UITableView?

IndexPath contains information about which row in which section the function is asking about. Base on this numbers you are configuring the cell to display the data for given row.


1 Answers

A bit late... but try this:

Where you want to clear the table:

// clear table
clearTable = YES;
[table reloadData];
clearTable = NO;

This function should look like:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if(clearTable)
        return 0;

    (...)
}
like image 182
joao Avatar answered Sep 28 '22 08:09

joao