xmartlabs / Eureka

Elegant iOS form builder in Swift
https://eurekacommunity.github.io
MIT License
11.78k stars 1.33k forks source link

When there is only one section, the section uses row.title as its default value #2127

Closed yunhao closed 3 years ago

yunhao commented 3 years ago

If we use PushRow to push a SelectorViewController with only one section, then the section title will be set to row.title by default, although we don't explicitly do so. Look at the 1st picture.

PushRow<String>() {
    $0.title = nil
    $0.selectorTitle = "Selector Title"
    $0.options = ["Row 0", "Row 1", "Row 2"]
}

The behavior, that the section title has a default value, is quite confusing. It's different from the default behavior of UITableView. The row title has a strong correlation with the pushed view controller title, but not with the section title.

Actually, when there is only one section, we only need a view controller title instead of a section title. Look at 2nd picture.

We should remove the default value, and let developers explicitly set the title if they need it.

kamerc commented 3 years ago

This change has caused problems in my project. How can I explicitly set the header title to be row.title if needed? The code change now always sets it to nil. It looks like I could maybe set the header title via optionProvider options but I haven't been able to figure out the right syntax for that. Is there a certain attribute I should use when creating the PushRow?

mats-claassen commented 3 years ago

You should be able to set section header using sectionKeyForValue and sectionHeaderTitleForKey on the SelectorViewController

kamerc commented 2 years ago

@mats-claassen that solution doesn't work for me because our design is that there is only 1 section, and that section needs a header title. sectionHeaderTitleForKey doesn't get called because optionsBySections returns nil. Therefore, my code reaches the else in setupForm where header is always set to nil. I don't see a way to override it.

mats-claassen commented 2 years ago

@kamerc for single section setups you could set sectionKeyForValue to a closure that always returns the same key, right? Then optionsBySections will not return nil and sectionHeaderTitleForKey will be used

kamerc commented 2 years ago

@mats-claassen that solution was going to be my workaround, I just wanted to know first if there was a better way. Is the best way to access sectionKeyForValue on the SelectorViewController via onPresent? For example, what I have below:

PushRow<string>(tag) {
$0.options = ['1', '2']
$0.onPresent { from, to in
    to.sectionKeyForValue = { option in
     return "my heading title"
    }
}
}
mats-claassen commented 2 years ago

Yes, that looks right