Uitableviewcell, Show Delete Button on Swipe

UITableViewCell, show delete button on swipe

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
}
}

Add swipe to delete UITableViewCell

Add these two functions:

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
// handle delete (by removing the data from your array and updating the tableview)
}
}

Swift 3.0:

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
// handle delete (by removing the data from your array and updating the tableview)
}
}

Swift 4.2

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == .delete) {
// handle delete (by removing the data from your array and updating the tableview)
}
}

How to show delete button in UITableViewCell without swiping/touching it like in Moda Operandi iOS app?

The native UITableViewRowAction does not support that, but you could write your own implementation or use a library.

e.g This one: MGSwipeTableCell,

Implement the cells and the delegate according to the documentation, then use the showSwipe method to display the swipe actions programmatically.

How to customize the Delete button shown when swipe a UITableViewCell

there is too much solutions... you should to search before posting new question. check this link:

iOS Programming 101: How To Create Swipeable Table View Cell to Display More Options

or use ready-made solutions like this:

https://github.com/CEWendel/SWTableViewCell

i can't post much links without 10 reputation, so try to google "custom delete button uitableviewcell"

UITableViewCell show delete button on tap

I eventually ended up using: MGSwipeTableCell



Related Topics



Leave a reply



Submit