UISegmentedControl delegate/Touch Events

Jab picture Jab · Jan 13, 2010 · Viewed 20.5k times · Source

I have a UISegmentedControl that has six segments, I want them to call a method when the value changes, but also when each segment gets a UIControlEventTouchDragIn because I want a UILabel to show up with it's name when the person is trying to select something on it and drags their finger across the control, but the segmented control does not sen this call even when I drag into the thing. Please help. Maybe I need to create UIButtons over the control that call methods upon a drag in, but call the value changed method when they recieve a tap.

Answer

Deratrius picture Deratrius · Aug 24, 2011

Maybe I don't understand your question correctly but couldn't you just use this:

[segmentedControl addTarget:self 
         action:@selector(action:)  
         forControlEvents:UIControlEventValueChanged];

and just replace the UIControlEventValueChanged by UIControlEventTouchDragIn? Then in your action method do whatever needs to be done such as changing the text of a UILabel.

I have a UITAbleView with a bunch of cells and an UISegmentedControll in each cell and it works just fine for me.

The documentation for UISegmentedControl seems to be unavailable online but you can see it in XCode's Organiser and the code above is the first example.