Created
February 7, 2018 22:36
-
-
Save EricADockery/521e83ba819dc08228e4db221c035c13 to your computer and use it in GitHub Desktop.
Example to creating multiple titles for headers in section given different layout options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum SectionTitle: String { | |
case a = "a" | |
case b = "b" | |
case c = "c" | |
case d = "d" | |
init?(section: Int, hasB: Bool = false, hasD: Bool = false) { | |
if hasD { | |
switch section { | |
case 0: self = .a | |
case 1: self = .b | |
case 2: self = .c | |
case 3: self = .d | |
default: return nil | |
} | |
} else { | |
switch section { | |
case 0: self = .a | |
case 1: | |
if hasB { | |
self = .b | |
} else { | |
self = .c | |
} | |
case 2: | |
self = .c | |
default: return nil | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | |
let hasB = true | |
let hasD = false | |
let title = SectionTitle(section: section, hasB: hasB, hasD: hasD) | |
return title?.rawValue ?? "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment