【发布时间】:2011-07-17 01:12:41
【问题描述】:
我知道这是非常基本的,但我需要澄清一下。我正在尝试开发一款 iPad 应用,但遇到了问题。我的解释可能需要太多信息,但请耐心等待。
我有两个 ViewController。一个叫做NewGameViewController,另一个叫做GameViewController。在 NewGameViewController 中,我像这样显示 GameViewController:
GameViewController *controller = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
所以这会在内存中创建一个 GameViewController 的实例。 GameViewController 中定义了一些 ivars 和方法。其中一个 ivars 是一个数组,当 GameViewController 加载时(在 viewWillAppear 方法中),它会与座位对象一起归档。
我还有一个叫做 player 的对象。这只是 UIView 的一个子类。当 GameViewController 加载时,它最多向子视图添加六个玩家对象。我需要每个玩家对象能够访问由 NewGameViewController 加载的 GameViewController 内存中的同一实例。我会在玩家对象中使用指针来访问 GameViewController 的同一个实例吗?我发现如果我将 GameViewController 的新实例加载到内存中并尝试使用它,则数组 ivar 往往是空的,因此无法使用。我如何确定指向 GameViewController 的指针指向正确的 GameViewController 实例?
【问题讨论】:
标签: objective-c ios xcode pointers uiviewcontroller