Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reordering sections and rows will return the same initial order and not the updated ones #2239

Open
DigitalVanilla opened this issue Jan 6, 2023 · 2 comments

Comments

@DigitalVanilla
Copy link

Hello

I needed to rearrange sections and rows programmatically and with drag'/drop functionality, but I did hit a small problem when I want to cycle again the form to get the data in the order after operations like move(fromOffsets: [0], toOffset: 2), but Im getting the same initial order and not the updated one.

My code:

form
    
    +++ Section() { section in
      section.tag = "anchor_1"
    }
    
    <<< EKIconTitleExtraRow() { row in
      row.tag = "row_1"
      row.icon = UIImage(named: "meal_details_icon")
      row.title = "Some row to move 1"
      row.value = "extra stuff"
    }
    
    <<< EKIconTitleExtraRow() { row in
      row.tag = "row_2"
      row.icon = UIImage(named: "meal_details_icon")
      row.title = "Some row to move 2"
      row.value = "extra stuff"
    }
    
    <<< EKIconTitleExtraRow() { row in
      row.tag = "row_3"
      row.icon = UIImage(named: "meal_details_icon")
      row.title = "Some row to move 3"
      row.value = "extra stuff"
    }
    
    +++ Section() { section in
      section.tag = "anchor_2"
    }
    
    <<< EKIconTitleExtraRow() { row in
      row.icon = UIImage(named: "meal_details_icon")
      row.title = "Some row to move 4"
      row.value = "extra stuff"
    }
    
    <<< EKIconTitleExtraRow() { row in
      row.icon = UIImage(named: "meal_details_icon")
      row.title = "Some row to move 5"
      row.value = "extra stuff"
    }
    
    <<< EKIconTitleExtraRow() { row in
      row.icon = UIImage(named: "meal_details_icon")
      row.title = "Some row to move 6"
      row.value = "extra stuff"
    }

then I move the first section below the second like:

form.move(fromOffsets: [0], toOffset: 2)

then I wish to see the order of the section tags:

print(self.form.allSections.map({ section in return section.tag }))

but Im getting always ["anchor_1", "anchor_2"] where I was expecting ["anchor_2", "anchor_1"]; and this is the same for the rows that I try to move using the native drag delegate, where visually I see the change in the order after the drop but if I cycle the section rows with allRows I get the same initial order.
What am I missing?

Thanks

@mats-claassen
Copy link
Member

Hi, have you tried using Multivalued Sections? There is an example in the example project and in the README. That is the case for which Eureka has reordering implemented.

If that doesn't suit your needs you could override these delegate functions in your FormViewController subclass:

    open func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool
    open func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath
    open func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)

They are implemented in Core.swift from line 873, if you need some guidance

@DigitalVanilla
Copy link
Author

Yeah, unfortunately I cannot use the Multivalued Sections because we need to move sections itself using a single row as "fake header" to rearrange; unfortunately Apple never gave us the ability to actually drag'n drop an entire section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants