Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 Tableview Delete Row Best Practice

Tags:

ios

row

tableview

enter image description here

On the iPhone there is a text book example of how to delete a tableview row in the Message Apps. This appears to use three separate views to perform the task.

My question is about whether there are short cuts to achieve this or do you just create three screens and to do the bleedin' obvious.

Many thanks.

like image 958
Edward Hasted Avatar asked Jan 12 '14 09:01

Edward Hasted


People also ask

How to delete a row from tableView?

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 I delete a simple Tableview in swift 5?

After that, we need to add the row into the table view at index path 0 and remove the values from the input textfield. Run the application and you can add the cell when you tap on Add Button. Now, we will Delete the cell from the tableview when use click on the Delete button on the cell.

How do you remove cells from a table view?

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.


1 Answers

Removing a row from storyboard is pretty straightforward. You just have to inherit 2 methods in your TableView Data source. First is telling if a row can be deleted:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

Second is removing the row from table view:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
like image 93
Damien Avatar answered Sep 25 '22 16:09

Damien