Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove the delete button ⛔️ on table rows in edit mode

I am trying to learn Swift, but there is a problem in my project that drives me nuts. I have a working list of data in a ViewController fed by parse.com. I managed to implement a swipe-feature that reveals buttons for both deleting and editing. That is working fine. Now I want the user to be able to reorder the cells. So I successfully implemented a button to put the table into editing-mode. My 2 problems with that are:

  1. When I enter edit-mode I just want to be able to reorder the cells since editing and deleting is done via swipe (via "tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath)". How can I achive that the user doesn't see the 2 buttons for deleting and editing when in editing-mode and touching the delete-circle that is provided automatically?

  2. Is it possible to remove the delete-circle altogether? Using "UITableViewCellEditingStyle.None" also disables the swipe-functionality.

Thanks in advance!

like image 634
Constantin Weber Avatar asked Nov 26 '15 20:11

Constantin Weber


People also ask

How to remove a delete row from a btndel object?

function SomeDeleteRowFunction (btndel) { if (typeof (btndel) == "object") { $ (btndel).closest ("tr").remove (); } else { return false; } } As @gaurang171 mentioned, we can use .closest () which will return the first ancestor, or the closest to our delete button, and use .remove () to remove it.

How to add & delete table rows in react app?

Now, you can add & delete Table rows yourself by running the React App with the following command After that, you can see the Add Delete Table rows UI by opening the following URL in your web browser Hey there, Welcome to CodingStatus. My Name is Md Nurullah from Bihar, India.

How do I delete a row in Salesforce?

Deleting a row requires a delete API service with only the id attached to the URL. Let’s add a new deleteUser function in the user.service.ts class: In the app.component.ts class, we will create a removeRow function that triggers the delete service.

How to remove a row from a node in a list?

Simplest and most straight forward answer. function SomeDeleteRowFunction () { // event.target will be the input element. var td = event.target.parentNode; var tr = td.parentNode; // the row to be removed tr.parentNode.removeChild (tr); } Following solution is working fine.


1 Answers

To avoid the round red delete button that appears when you put set UITableView isEditing to true at the left and does nothing when you click it, the minimum that worked for me was this (Swift 4, iOS 11)

// Avoid the round red delete button on the left of the cell:

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


func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return .none
}

I also have these functions, which probably interact:

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

// Including this function in the delegate enable left-swipe deleting
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
    if editingStyle == .delete {
        savedConversions.remove(at: indexPath.row)
    }
}


// Including this function enables reordering
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath,to destinationIndexPath: IndexPath)
{
    let elem = savedConversions.remove(at: sourceIndexPath.row)
    savedConversions.insert(elem, at: destinationIndexPath.row)
}
like image 56
MarkAurelius Avatar answered Nov 14 '22 22:11

MarkAurelius