Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Last active October 16, 2015 20:34
Show Gist options
  • Save abbeyjackson/06352bca2d626d2f69cc to your computer and use it in GitHub Desktop.
Save abbeyjackson/06352bca2d626d2f69cc to your computer and use it in GitHub Desktop.
Multiple buttons with same protocol - delegate function, using multiple IBActions instead of tags
in tabBar.swift
protocol TabBarDelegate {
func buttonPressed(tabBar: TabBar, section: SectionType)
}
var delegate: TabBarDelegate?
@IBAction func buttonAPressed(sender: UIButton){
delegate?.buttonPressed(self, section: SectionType.caseA)
}
@IBAction func buttonBPressed(sender: UIButton){
delegate?.buttonPressed(self, section: SectionType.caseB)
}
func buttonPressed(tabBar: TabBar, section: SectionType) {
if arrayForSectionType(section).count > 0 {
tableView.scrollToRowAtIndexPath( (NSIndexPath(forRow: 0, inSection: section.rawValue)), atScrollPosition: .Top, animated: true)
}
}
func arrayForSectionType(type: SectionType) -> Array<FieldType> {
switch type {
case .CaseA:
return arrayA
case .CaseB
return arrayB
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment