Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell, show delete button on swipe

How do I get the delete button to show when swiping on a UITableViewCell? The event is never raised and the delete button never appears.

like image 931
TheLearner Avatar asked Jul 22 '10 13:07

TheLearner


People also ask

How to delete table view cell in Swift?

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.

What is Table View delegate?

- tableView:willDisplayCell:forRowAtIndexPath: Tells the delegate the table view is about to draw a cell for a particular row. - tableView:indentationLevelForRowAtIndexPath: Asks the delegate to return the level of indentation for a row in a given section.


1 Answers

During startup in (-viewDidLoad or in storyboard) do:

self.tableView.allowsMultipleSelectionDuringEditing = false 

Override to support conditional editing of the table view. This only needs to be implemented if you are going to be returning NO for some items. By default, all items are editable.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {     // Return YES if you want the specified item to be editable.     return YES; }  // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {     if (editingStyle == UITableViewCellEditingStyleDelete) {         //add code here for when you hit delete     }     } 
like image 72
Kurbz Avatar answered Oct 16 '22 17:10

Kurbz