get string value from UISegmentedControl

IosIphoneUisegmentedcontrol

Ios Problem Overview


How can I get the text value of a segment in a UISegmentedControl?

Ios Solutions


Solution 1 - Ios

Objective-C

NSString *title = [segment titleForSegmentAtIndex:segment.selectedSegmentIndex];

Swift:

let title = segment.titleForSegment(at: segment.selectedSegmentIndex)

Solution 2 - Ios

[segmentedControl titleForSegmentAtIndex:int];

For the current selected index

[segmentedControl titleForSegmentAtIndex:[segmentedControl selectedSegmentIndex]];

Solution 3 - Ios

Swift 3:

segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex)

Solution 4 - Ios

As this is the first Google result and we are now in the swift era:

Swift:

seg_ctrl.titleForSegmentAtIndex( seg_ctrl.selectedSegmentIndex)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMatt S.View Question on Stackoverflow
Solution 1 - IosKevin SylvestreView Answer on Stackoverflow
Solution 2 - IosBrandon BodnarView Answer on Stackoverflow
Solution 3 - IosEcnalyrView Answer on Stackoverflow
Solution 4 - IosJohnView Answer on Stackoverflow