-1

I'm really stumped on this. I've read in a few different spots on how to implement this and can't seem to get it right for me. Perhaps if I spell out my concerns directly someone can help me better understand.

I have 2 UIViewControllers (HomeController and Game Controller) wrapper in a UINavigationController.

To start the game, I would like to pass an int from the HomeController to the GameController (easy, medium or hard). I have 3 buttons set up to Actions which assign the value. From there ... ???

I looked into custom segues, regular segues, no segues. I have the integer set up as a property on the GameController, but I don't know how to access it.

Thanks for your patience as I am a real beginner with xCode.

Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ehren
  • 171
  • 3
  • 14

1 Answers1

-1

Simple way to do:

HomeController .m, This will call by clicking on some button of yours:

-(void)firstButtonPress: (UIButton *)button
{
    GameController *gameView = [[GameController alloc]initWithGameNumber:2];
    [self presentViewController:gameView animated:YES completion:nil];
}

And you pass it by the "init" method:

GameController h.

@interface GameController : UIViewController
@property (nonatomic) int gameNumber;


- (id)initWithGameNumber: (int)gameNumber;


@end

GameController m.

@interface GameController ()

@end

@implementation GameController

- (id)initWithGameNumber: (int)gameNumber
{
    self = [super init];
    if (self) {
        self.gameNumber = gameNumber;
    }
    return self;
}

@end

And the value has been passed, There are several ways of doing this, this is just a basic one. I would recommend you to start with a tutorial first:

http://www.raywenderlich.com/25561/learn-to-code-ios-apps-3-your-first-app

Hope this helps

MCMatan
  • 8,623
  • 6
  • 46
  • 85