title: Swift:How to make SegmentedControl notice value change done by swiping?
body: <p>I have segmented control inside the UITableViewCell custom class. I added swipe gesture to enable modifying the value also by swipe. Inside the cellForRowAtIndexPath method.
  In awakeFromNib() method in  I add this line:</p>
  
  <pre><code>segmentControl.addTarget(self, action: "segmentValueChanged:", forControlEvents: .ValueChanged)
  </code></pre>
  
  <p>to observe changes to the value of segmented control.
  Here is the implementation of mentioned method</p>
  
  <pre><code>    func segmentValueChanged(sender: AnyObject){
  
      if segmentControl.selectedIndex == 0 {
  
          segmentControl.thumbColor = UIColor(red: 231.0/255.0, green: 76.0/255.0, blue: 60.0/255.0, alpha: 1.0)
          segmentControl.selectedLabelColor = UIColor.whiteColor()
          segmentControl.unselectedLabelColor = UIColor.grayColor()
  
  
      }else if segmentControl.selectedIndex == 1{
  
          segmentControl.thumbColor = UIColor(red: 46.0/255.0, green: 204.0/255.0, blue: 113.0/255.0, alpha: 1.0)
          segmentControl.selectedLabelColor = UIColor.grayColor()
          segmentControl.unselectedLabelColor = UIColor.whiteColor()
  
      }
  </code></pre>
  
  <p>Here is my function that handles swipes</p>
  
  <pre><code> func handleSwipes(sender:UISwipeGestureRecognizer)
  
      {
          if segmentControl.selectedIndex == 1 &amp;&amp; sender.direction == .Left
  
          {
  
              self.segmentControl.selectedIndex = 0
  
          }
  
          if segmentControl.selectedIndex == 0 &amp;&amp; sender.direction == .Right
  
          {
  
              self.segmentControl.selectedIndex = 1
  
          }
  
      }
  </code></pre>
  
  <p>The problem is: When I swipe segmentValueChanged does not notice any change is selectedIndex value? 
  I tried playing around with target and senders, but without any good result unfortunately</p>
  
  <p>Thanks in advance</p>
  
  <p>EDIT:</p>
  
  <p>I add gesture inside cellForRowAtIndexPath</p>
  
  <p>let leftSwipe = UISwipeGestureRecognizer(target: cell, action: Selector("handleSwipes:"))</p>
  
  <pre><code>    let rightSwipe = UISwipeGestureRecognizer(target: cell, action: Selector("handleSwipes:"))
  
   leftSwipe.direction = .Left
  
   rightSwipe.direction = .Right
  
   cell.segmentControl.thumbView.addGestureRecognizer(leftSwipe)
  
   cell.segmentControl.thumbView.addGestureRecognizer(rightSwipe)
  </code></pre>
  
  <p>EDIT: 
  In custom segment control I found this method, maybe editing it could solve the issue, but I do not have idea how to do that</p>
  
  <pre><code>override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -&gt; Bool {
  
      let location = touch.locationInView(self)
  
      var calculatedIndex : Int?
      for (index, item) in labels.enumerate() {
          if item.frame.contains(location) {
              calculatedIndex = index
          }
      }
  
  
      if calculatedIndex != nil {
          selectedIndex = calculatedIndex!
          sendActionsForControlEvents(.ValueChanged)
      }
  
      return false
  }
  </code></pre>