Victor Rius Victor Rius - 1 year ago 270
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);


Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download