Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting the tapped segment of a UISegmentedControl

I have placed an UISegmentedControl into my XIB file. Basically, when the the second tab of the control is tapped (aka segment 1, the first segment is segment 0), I want to unhide a text field. I know how to unhide the text field, but how do I detect which part of the segmented control the user has tapped?

[textField setHidden:NO];
like image 923
Jack Humphries Avatar asked Jul 12 '11 17:07

Jack Humphries


2 Answers

Create an IBAction like the one below and connect it to the valueChanged action in Interface Builder.

- (IBAction)segmentedControlChanged:(id)sender
{
   UISegmentedControl *s = (UISegmentedControl *)sender;

   if (s.selectedSegmentIndex == 1)
   {
      [countTextField setHidden:NO];
   }
}
like image 65
Brandon Schlenker Avatar answered Nov 19 '22 19:11

Brandon Schlenker


You should hook up your segmeted controls valueChanged action in IB to a method in your view controller that checks your segmented controls selectedSegmentIndex.

like image 36
thelaws Avatar answered Nov 19 '22 19:11

thelaws