NSSegmentedControl -selectedSegment always returns 0

Posted by SphereCat1 on Stack Overflow See other posts from Stack Overflow or by SphereCat1
Published on 2010-05-17T00:34:57Z Indexed on 2010/05/17 0:40 UTC
Read the original article Hit count: 236

I have an NSSegmentedControl with two segments set to "Select None" mode in Interface Builder. No matter what I try, I can't get -selectedSegment to return anything but 0, even though segment 0 is even disabled by default and can't possibly be selected. Here's the relevant function that gets called when you click any segment on the control:

-(IBAction)changeStep:(id)sender
{
    [stepContainer setHidden:TRUE];
    [(NSView *)[[wizard stepArray] objectAtIndex:(NSInteger)[wizard step]] removeFromSuperview];
    switch ([[navigationButton cell] selectedSegment])
    {
    case 0:
        [wizard setStep:(NSInteger *)[wizard step]-1];
        break;
    case 1:
        [wizard setStep:(NSInteger *)[wizard step]+1];
        break;
    default:
        break;
    }
    //[[navigationButton cell] setSelected:FALSE forSegment:[navigationButton selectedSegment]];

    if ([wizard step] > 0)
    {
        [wizard setStep:0];
        [navigationButton setEnabled:FALSE forSegment:0];
    }

    NSLog(@"%d", [wizard step]);
    [stepContainer addSubview:(NSView *)[[wizard stepArray] objectAtIndex:(NSInteger)[wizard step]]];
    [stepContainer setHidden:FALSE withFade:TRUE];
}

I've also tried using -isSelectedForSegment, but it has the same result.
Any help you can provide would be awesome, I have no idea what I'm doing wrong. Thanks!
SphereCat1

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa