Victor Rius Victor Rius - 7 months ago 111
Objective-C Question

Segmented Control Text Objective-c

How can I save in a NSString the text of the segment I clicked? Now I only obtain the index.

- (IBAction)segmentedControlShortcuts:(id)sender {

NSString *shortcutText = [NSString stringWithFormat:@"%ld",(long)segmentedControlShortcuts.selectedSegmentIndex];
NSLog(@"%@", shortcutText);



The sender will be the UISegmentedControl, so you just need to cast it and use titleForSegmentAtIndex.

- (IBAction)segmentedControlShortcuts:(id)sender {
    UISegmentedControl *control = (UISegmentedControl *)sender;
    NSString *shortcutText = [control titleForSegmentAtIndex:control.selectedSegmentIndex];