开发者

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.h开发者_Python百科idden = YES;
        rightSwitch.hidden = YES;
        doSomethingButton.hidden = NO;
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜