0

I have a segmented control (Added via story board) and have set two segments (set in story board). When it is clicked it fires my 'segmentedIndexChanged:' method, but in that method i can't get the values (it always returns null) for either .selectedSegmentedIndex or titleForSegmentedAtIndex

-(IBAction) segmentedIndexChanged {

    NSLog(@"index, text value: %@ , %@", self.mySegControl.selectedSegmentIndex, [mySegControl titleForSegmentAtIndex:mySegControl.selectedSegmentIndex]

 );
    switch (self.mySegControl.selectedSegmentIndex) {
        case 0:

            NSLog(@"segmented 1 selected");
            break;
        case 1:
            NSLog(@"segmented 2  selected");

            break;

        default:
            break;
    }


}

any ideas why?

1 Answer 1

1

Are you sure the outlet is connected to the control? You can check by printing out NSLog(@"%@", self.mySegControl)

Also, usually, IBActions should have the form of - (IBAction)action:(id)sender, that way you would be able to access the sender (in this case the segmented control) without having an outlet to it as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.