Search code examples
ioseureka-forms

Why can't delete row in Eureka demo?


)

I try learn something from Eureka Demo, but when I enter Eureka Demo App :

Multivalued Sections -> select any row (e.g:Multivalued Only Delete):

how can I delete any row???

I can't tap left delete button to delete any row,why?

and source code is here:

class MultivaluedOnlyDeleteController: FormViewController {

  @IBOutlet weak var editButton: UIBarButtonItem!

  override func rowsHaveBeenRemoved(_ rows: [BaseRow], at indexes: [IndexPath]) {
      print("delete row")
  }

  override func viewDidLoad() {
      super.viewDidLoad()
      tableView.isEditing = false
      let nameList = ["family", "male", "female", "client"]

      let section = MultivaluedSection(multivaluedOptions: .Delete, footer: "you can swipe to delete when table.isEditing = false (Not Editing)")


      for tag in nameList {
          section <<< TextRow {
                          $0.placeholder = "Tag Name"
                          $0.value = tag
                      }
      }


      let section2 =  MultivaluedSection(multivaluedOptions: .Delete, footer: "")
      for _ in 1..<4 {
          section2 <<< PickerInlineRow<String> {
                          $0.title = "Tap to select"
                          $0.value = "client"
                          $0.options = nameList
                       }
      }

      editButton.title = tableView.isEditing ? "Done" : "Edit"
      editButton.target = self
      editButton.action = #selector(editPressed(sender:))

      form    +++

              section

              +++

              section2
  }

  @objc func editPressed(sender: UIBarButtonItem){
      tableView.setEditing(!tableView.isEditing, animated: true)
      editButton.title = tableView.isEditing ? "Done" : "Edit"

  }
}

I don't know If I miss something???

thanks


Solution

  • The issue in the demo is that they have missing add actions in the cell

    CurrentCode Code

        for tag in nameList {
            section <<< TextRow {
                            $0.placeholder = "Tag Name"
                            $0.value = tag
    
                        }
        }
    

    Fixed Code

        for tag in nameList {
            section <<< TextRow {
                            $0.placeholder = "Tag Name"
                            $0.value = tag
    
                            let deleteAction = SwipeAction(style: .destructive, title: "Delete") { (action, row, completionHandler) in
                                print("Delete")
                                completionHandler?(true)
                            }
    
                            $0.trailingSwipe.actions = [deleteAction]
                        }
        }
    

    fixed issue demo code in gihub, on my fork https://github.com/rmelian2014/Eureka