Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

UISegmentedControl and Touch events

Hi,

does anyone know how you get touch events from a UISegmentedControl?

I have done this.


UISegmentedControl * mySegmentedControl = [[UISegmentedControl alloc] initWithFrame:ButtonsRect];


mySegmentedControl.momentary = YES;
mySegmentedControl.segmentedControlStyle = UISegmentedControlStyleBordered;

[mySegmentedControl insertSegmentWithTitle:@"some text" atIndex:0 animated:NO];

[mySegmentedControl addTarget:self action:(SEL)@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];



I have implemented a method called buttonPressed, but it never gets called.

What am I missing?

Thanks

Adrian

MacBook, Mac OS X (10.5.2), 2Gb Ram

Posted on May 14, 2008 9:39 AM

Reply
7 replies

Jun 3, 2008 2:23 PM in response to ooo27

The problem is, if you want to (as I do in one application) act on a second (or subsequent) press AFTER that particular segment is already selected. Now there is no UIControlEventValueChanged generated. I have yet to find a solution.

Using touchesBegan:touches withEvent:event can detect touches elsewhere in the view (for example, the background), but it does not respond to a touch in the segmented control.

I suppose I need to subclass one of the methods of UIControl, but I'm wary of doing that.

Jul 31, 2008 12:57 PM in response to Steve Patt

I have created a UISegmentedControl using IB and have assigned my function to the Value Changed event. My view loads properly, but as soon as I touch the control the app crashes. I have tried all the events listed in IB for that control and none of them appear to respond to a touch except for the Vallue Changed event. But that event leads to a crash. Has anyone setup a Segmented Control is IB and got it to do something when the buttons are pressed?

Right now all I'm trying to do is have it output to the NSLog which button is selected.

Thanks,
David

UISegmentedControl and Touch events

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.