Created
October 16, 2015 20:33
-
-
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)
This file contains hidden or 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
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