Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically set the selected state for a segment in UISegmentedControl

I have four segments in my UISegmentedControl. I am trying to programmatically set the selected state of the third and fourth segments at the same time if the user has selected the first segment.

Example: In a given segmented control, if the user selected segment A, then C, D should be selected.

I looked into Apple's methods but found none that match my requirement. I am looking for a method that would look like-

Any help on this is much appreciated.


-(void) setSelected: (BOOL) selected forSegmentAtIndex: (NSUInteger) segment

Parameters

enabled

YES to select the specified segment or NO to unselect the segment. By default, segments are unselected.

segment

An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.


like image 955
Revanth Avatar asked May 03 '14 23:05

Revanth


2 Answers

Swift 4.0

segmentedControl.selectedSegmentIndex = index
like image 198
Abhishek Jain Avatar answered Oct 07 '22 01:10

Abhishek Jain


Use setSelectedSegmentIndex like so -

[mySegmentControl setSelectedSegmentIndex:index]
like image 37
indyfromoz Avatar answered Oct 07 '22 01:10

indyfromoz