0

I can not figure out what I am doing wrong nothing happens when the methods are called.

Declared in the interface of the class

ViewController* mainMenu;

- (id)initWithSize:(CGSize)size {

    if (self = [super initWithSize:size]) {
        mainMenu = [[ViewController alloc] init];

        ....
    }
}

- (void)pauseEnabled {
    //  mainMenu.pauseButton.hidden = NO;
    //  mainMenu.pauseButton.enabled = YES;
    [mainMenu.pauseButton setHidden:NO];
    [mainMenu.pauseButton setEnabled:YES];
}

- (void)pauseDisabled {
    mainMenu.pauseButton.hidden = YES;
    mainMenu.pauseButton.enabled = NO;
}

- (void)startGame {
    [self pauseEnabled];
    ......
}
2
  • You shouldn't name your mainMenu view controller class "ViewController". Why not something much more intuitive, like "MainMenuViewController" or "MainViewController"? Commented Mar 1, 2014 at 20:49
  • 1
    A view controller should control its own view... hence its name... Commented Mar 1, 2014 at 20:55

2 Answers 2

1

When you run:

mainMenu = [[ViewController alloc] init];

you're creating a new view controller whose view isn't loaded and which is never shown on screen. You need to get an instance of ViewController which is actually presented on screen so that you can send it messages. How you do that depends very much on the structure of your app and what creates the ViewController.

Your usage of initWithSize: indicates that this object isn't a controller itself. In this case you may want to rethink what you're doing and, rather than have this class maintain a reference to a view controller, instead pass it a reference to the button that it should interact with when it is created.

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

Comments

0

Make sure that the pauseButton is wired to the outlet in the storyboard / xib file. Basically, make sure it is not nil. Also verify if you are adding the mainMenu's view to the view hierarchy.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.