UISegmentedControl Cut Segment Detection

I put the UISegmentedControl in my XIB file. Basically, when the second tab of the control is selected (aka segment 1, the first segment is segment 0), I want to display a text box. I know how to display a text box, but how do I determine which part of a segmented control a user clicked on?

[textField setHidden:NO]; 
+7
source share
3 answers

You must connect your segmeted valueChanged valueChanged in IB to a method in your view controller that checks your segmented selectedSegmentIndex controls.

+11
source

Create an IBAction as shown below and attach it to the valueChanged action in Interface Builder.

 - (IBAction)segmentedControlChanged:(id)sender { UISegmentedControl *s = (UISegmentedControl *)sender; if (s.selectedSegmentIndex == 1) { [countTextField setHidden:NO]; } } 
+21
source

You must add the target action for the UIControlEventValueChanged control UIControlEventValueChanged and check the selectedSegmentIndex segmented control.

If it is 1 , hide the text box.

+3
source

All Articles