Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Last active October 16, 2015 20:30
Show Gist options
  • Save abbeyjackson/22b8684261d2f87b72f9 to your computer and use it in GitHub Desktop.
Save abbeyjackson/22b8684261d2f87b72f9 to your computer and use it in GitHub Desktop.
multiple buttons and one delegate function, using tags and protocol, in Swift
in UIViewController:
import UIKit
class tempViewController: UIView {
var array : NSArray
func buttonPressed(navigationBar: ScrollBar, sender: UIButton) {
switch sender.tag {
case 0:
array = arrayA
case 1:
array = arrayB
}
if(arrayA.count > 0) {
tableView.scrollToRowAtIndexPath((NSIndexPath(forRow: 0, inSection: sectionA)), atScrollPosition: .Top, animated: true)
}
}
}
import UIKit
protocol ScrollBarDelegate {
func buttonPressed(scrollBar: ScrollBar, sender: UIButton)
}
class tempScrollBar: UIView {
weak var delegate: ScrollBarDelegate?
@IBAction func buttonPressed(sender: UIButton) {
delegate?.buttonPressed?(self, sender: sender)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment