Advertisement
Guest User

SegmentedControlTableViewDelegateExample.swift

a guest
Oct 25th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.84 KB | None | 0 0
  1. import UIKit
  2.  
  3.  
  4. protocol SegmentedControlTableViewCellDelegate: class {
  5.     func handleSegmentedControlValueChanged(to newValue: Int, inCell: UITableViewCell)
  6. }
  7.  
  8. class SomeTableViewCellSubclass: UITableViewCell {
  9.     var segmentedCellDelegate: SegmentedControlTableViewCellDelegate?
  10.    
  11.     @IBAction func valueChangedIn(segmentedControl: UISegmentedControl) {
  12.         segmentedCellDelegate?.handleSegmentedControlValueChanged(to: segmentedControl.selectedSegmentIndex, inCell: self)
  13.     }
  14. }
  15.  
  16. class YourTableViewControllerSubclass: UITableViewController {
  17.         // Whatever logic you have
  18. }
  19.  
  20. extension YourTableViewControllerSubclass: SegmentedControlTableViewCellDelegate {
  21.     func handleSegmentedControlValueChanged(to newValue: Int, inCell: UITableViewCell) {
  22.         // Whatever you want to happen in your ViewController
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement