如何设置一个班级两步?

时间:2010-08-02 17:14:34

标签: iphone objective-c properties class

我有点困惑如何设置一个比最顶层的课程低两级的课程。

例如,假设我有一款名为BoardGame的游戏。其中一个参数在numberOfSquares。

这些类的设置如下:

BoardGameSetupViewController > BoardGamePlayViewController > GameEngine

BoardGameSetupViewController在选择了正方形数后创建了BoardGamePlayViewController的实例。 BoardGamePlayViewController将GameEngine类作为@property进行了@synthesised。

那么我如何直接从BoardGameSetupViewController设置GameEngine?例如设置numberOfSquares?

所以在BoardGameSetupViewController中,我想设置引擎的属性,但它们似乎没有被传递。

BoardGamePlayViewController *boardGamePlayViewController = [[BoardGamePlayViewController alloc] initWithNibName:@"BoardGameView" bundle:nil];

// this line doesn't work
boardGamePlayViewController.gameEngine.numberOfSquares = 12;

1 个答案:

答案 0 :(得分:3)

你首先需要创建一个GameAEngine的实例,如果你做任务boardGamePlay ViewController.game Engine.number Of Squares = 12;所以,

GameEngine *gameEngine = [[GameEngine alloc] init];
boardGamePlayViewController.gameEngine = gameEngine;
boardGamePlayViewController.gameEngine.numberOfSquares = 12;

应该有用。