Search code examples
ioseureka-forms

Strange behavior with MultivaluedSection?


)

I have been using Eureka for a while,It's amazing!!!

Recently I work on with MultivaluedSection,I write a simple project for test : It simple add/delete person from tableView.

here are code , first for model : Person

struct Person:Equatable,CustomStringConvertible{
    var description: String{
        return "\(name) \(id)"
    }

    static func ==(lhs: Person, rhs: Person) -> Bool {
        return lhs.id == rhs.id
    }

    var id:String
    var name:String

    init(name:String){
        self.id = UUID().uuidString
        self.name = name
    }
}

next code for VC :

class ViewController: FormViewController {

    var people:[Person] = []

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //hide delete button at row left
        tableView.isEditing = false
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let peopleSection = MultivaluedSection(multivaluedOptions:[.Delete,.Reorder,.Insert],header:"people")

        peopleSection.tag = "people"
        peopleSection.multivaluedRowToInsertAt = {idx in
            let newRow = LabelRow(){row in
                let person = Person(name: "h\(idx)")
                row.value = person.description
                self.people.append(person)

                let deleteAction = SwipeAction(style: .destructive, title: "DEL"){action,row,completion in
                    completion?(true)
                }
                row.trailingSwipe.actions = [deleteAction]
            }
            return newRow
        }

        peopleSection.addButtonProvider = {section in
            let addBtn = ButtonRow("add"){row in
                row.title = "new person"
            }
            return addBtn
        }

        form +++ peopleSection
    }
}

Run app , like the following picture:

enter image description here

There are 2 questions :

1:You can see when I add 3 person then delete them in order , everything is fine! But when I add person again some wrong is happened : it seem like the section's header was pulled very long. why???

2:When I added some people to tableView,there're title are not left-aligned,Why is that :

enter image description here

Thanks a lot!


Solution

  • Please update the code,

    peopleSection.multivaluedRowToInsertAt = {idx in
        return LabelRow() {
            let person = Person(name: "h\(idx)")
            $0.title = person.description
            self.people.append(person)
        }
    }
    

    It will give you following output, and delete will also work properly.

    enter image description here