Search code examples
iphoneiosios4uiswitch

switch.hidden = YES not working, outlets all correctly set up


I am having a problem that is totally confounding me. Please look at the code below, it is from the book "Beginning iPhone 4 Development" chapter 4. I'm new to this :)

- (IBAction)toggleControls:(id)sender
{
    if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
    {
        NSLog(@"Show switches");
        [self.leftSwitch setHidden:NO];
        [self.rightSwitch setHidden:NO];
        [self.doSomethingButton setHidden:YES];
    } 
    else
    {
        NSLog(@"Hide switches");
        [self.leftSwitch setHidden:YES];
        [self.rightSwitch setHidden:YES];
        [self.doSomethingButton setHidden:NO];
    }

}

The strange thing is that it logs this correctly but the ui controls aren't hiding/showing. I also tried this (original in book):

- (IBAction)toggleControls:(id)sender
{
    if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
    {
        NSLog(@"Show switches");
        leftSwitch.hidden = NO;
        rightSwitch.hidden = NO;
        doSomethingButton.hidden = YES;
    } 
    else
    {
        NSLog(@"Hide switches");
        leftSwitch.hidden = YES;
        rightSwitch.hidden = YES;
        doSomethingButton.hidden = NO;
    }
}

Solution

  • It sounds like you may have forgotten to wire up your outlets in Interface Builder. Check the values of leftSwitch and rightSwitch when this method is called by using a break point or an NSLog.