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.
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.
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.
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.
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With