EurekaCommunity / SplitRow

A row for Eureka to put two rows side by side into the same UITableViewCell
MIT License
56 stars 27 forks source link

Selecting an option from PushRow doesn't present the value back on rowLeft #13

Closed alonreptor closed 6 years ago

alonreptor commented 6 years ago

Please advise

marbetschar commented 6 years ago

@alonreptor please make sure you are not adding any onChange handler in the embedded PushRow, since SplitRow relies on this to get notified about changes.

If you need to listen for changes, you should do so by adding an onChange handler on the SplitRow itself.

Does this fix your issue?

alonreptor commented 6 years ago

Thanks for the quick response.

I tried: .onChange{ print($0.value?.left)} after SplitRow... but with no success

is there an example somewhere?

marbetschar commented 6 years ago

there is an example in the readme: https://github.com/EurekaCommunity/SplitRow

and if you download the repo, you can run the Example app which contains several examples in the ViewController:

https://github.com/EurekaCommunity/SplitRow/blob/master/Example/ViewController.swift

kamerc commented 6 years ago

@alonreptor are you setting a tag value on rowLeft? I found during my own development that if I had a tag value set on rowLeft, the value was getting cleared out whenever I changed the value of rowRight. In my case, rowLeft is an ActionSheet and rowRight is an EmailRow

alonreptor commented 6 years ago

Thanks All! @kamerc, I took your advise and simply changed the type of rowLeft to an ActionSheet. Now values are presented after selecting.

marbetschar commented 6 years ago

@alonreptor can you please provide thecode which does not work as expected on your end?

marbetschar commented 6 years ago

@alonreptor, sorry misunderstood your last post. Thought that it still does not work. I‘ll close this issue for now. Feel free to get in contact if you run in further problems.

alonreptor commented 6 years ago

@marbetschar just replace type of row: ActionSheetRow back to pushRow

alonreptor commented 6 years ago

` func buildSectionSamples(form:Form) {

    form
        +++ MultivaluedSection(
        multivaluedOptions: [.Insert,.Delete,],
        header: "Samples",
        footer: ""){
            $0.multivaluedRowToInsertAt = { _ in
                return SplitRow<ActionSheetRow<String>,TextRow>(){
                    $0.title = "Sample"
                    $0.rowLeftPercentage = 0.7
                    $0.rowLeft = ActionSheetRow<String>(){
                        $0.tag = "sampleleft"
                        $0.options = self.sampleList as! [String]
                        $0.value = "Select Sample"
                    }
                    $0.rowRight = TextRow(){
                        $0.tag = "Quantity"
                        $0.placeholder = "Quantity"
                        }.cellUpdate{ cell, row in
                            cell.textField?.clearButtonMode = .whileEditing
                            cell.textField?.textAlignment = .right
                    }
                }
            }
            guard let row = $0.multivaluedRowToInsertAt?(0) else{ return }
            $0 <<< row
    }
}`
marbetschar commented 6 years ago

Below you'll find a fixed version, using PushRow. Please note that, as @kamerc pointed out, SplitRow uses preconfigured tags for the embedded rows to set the new values correctly. Therefore, if you need a tag, you should set it for the entire SplitRow.

form
    +++ MultivaluedSection(
        multivaluedOptions: [.Insert,.Delete,],
        header: "Samples",
        footer: ""){
            $0.multivaluedRowToInsertAt = { _ in
                return SplitRow<PushRow<String>,TextRow>(){
                    $0.tag = "sampleQuantity" //sets the tag for the entire SplitRow
                    $0.title = "Sample"
                    $0.rowLeftPercentage = 0.7

                    $0.rowLeft = PushRow<String>(){
                        $0.options = ["a","b","c"]
                        $0.value = "Select Sample"
                    }

                    $0.rowRight = TextRow(){
                        $0.placeholder = "Quantity"
                    }.cellUpdate{ cell, row in
                        cell.textField?.clearButtonMode = .whileEditing
                        cell.textField?.textAlignment = .right
                    }

                // use an onChange handler on the SplitRow to
                // get notified whenever an embedded row changes its value
                }.onChange{ row in
                    print(row.tag,":didChange:value:",row.value)
                }
            }
            guard let row = $0.multivaluedRowToInsertAt?(0) else{ return }
            $0 <<< row
    }
alonreptor commented 6 years ago

@marbetschar Thank you very much!