Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Created October 16, 2015 20:33
Show Gist options
  • Save abbeyjackson/783df32b619f6966b940 to your computer and use it in GitHub Desktop.
Save abbeyjackson/783df32b619f6966b940 to your computer and use it in GitHub Desktop.
from @jazbo, custom tab bar using tags and no duplicate methods (one IBAction, one delegate method)
protocol SectionSelected {
func sectionSelected(section: SectionType)
}
class TestClass {
weak var tabBarDelegate: SectionSelected?
var sectionType: SectionType? {
didSet {
sectionSelected()
}
}
func buttonPressed(sender: UIButton) {
switch sender.tag {
case 1:
self.sectionType = SectionType.One
case 2:
self.sectionType = SectionType.Two
case 3:
self.sectionType = SectionType.Three
default: break
}
}
// MARK: - Helper Methods
func sectionSelected() {
guard let tabBarDelegate = tabBarDelegate, sectionType = sectionType else {
return
}
tabBarDelegate.sectionSelected(sectionType)
}
}
class Two: SectionSelected {
func sectionSelected(section: SectionType) {
// use selected section here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment