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

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

Closed
yunhao opened this issue Dec 18, 2020 · 6 comments · Fixed by #2128
Closed

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

yunhao opened this issue Dec 18, 2020 · 6 comments · Fixed by #2128

Comments

@yunhao
Copy link
Contributor

yunhao commented Dec 18, 2020

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
Copy link
Contributor

kamerc commented Sep 14, 2021

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
Copy link
Member

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

@kamerc
Copy link
Contributor

kamerc commented Mar 22, 2022

@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
Copy link
Member

@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
Copy link
Contributor

kamerc commented Mar 24, 2022

@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
Copy link
Member

Yes, that looks right

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

Successfully merging a pull request may close this issue.

3 participants