How do I switch UIsegmentedControll programmatically?

Voloda2 picture Voloda2 · Mar 11, 2011 · Viewed 35.5k times · Source

How do I switch UISegmentedControll programmatically ?

Answer

Lachlan Roche picture Lachlan Roche · Mar 11, 2011

The selectedSegmentIndex property identifies the selected segment of a UISegmentedControl. Set this property to the any valid segment index, or UISegmentedControlNoSegment (-1) to turn off the current selection.

// select the first segment
segmented.selectedSegmentIndex = 0;

// turn off the current selection
segmented.selectedSegmentIndex = UISegmentedControlNoSegment;