Iphone 应用程序开发 - 如何重新加载(?)视图?
好的,我正在开发 iPhone 游戏。您从菜单屏幕开始,然后选择“新游戏”或“高分”。让我们选择“新游戏”。
第一次执行此操作时,您会收到一条提醒,告诉您如何玩游戏。我用 - (id)initWithNibName 函数实现了这一点。这是确切的代码:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
//Alert Here
}
return self;
}
它效果很好。但是,如果我返回主菜单,然后返回游戏屏幕,则不会弹出此警报(仅在用户第一次单击“新游戏”时弹出)。
我还使用了 viewDidLoad 函数,只是作为旁注。
这是我用来实现我的笔尖的代码(我相信):
[mainViewController viewWillAppear:YES];
[introViewController viewWillDisappear:YES];
[introView removeFromSuperview];
[self.view addSubview:mainView];
[self.view insertSubview:menuButton aboveSubview:mainViewController.view];
[introViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
再一次, 非常感谢
Okay, I'm working on a iPhone game. You start off on a menu screen, then select "New Game" or "High Scores". Let's select "New Game."
The first time you do this, you get an alert telling you how to play the game. I implemented this with the - (id)initWithNibName function. Here is the exact code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
//Alert Here
}
return self;
}
It works great. However, if I go back to the main menu, then return to the game screen, this alert does not pop up (it only pops up the first time the user clicks "New Game").
I am also using an viewDidLoad function, just as a side note.
Here is the code I am using to implement my nib (I believe):
[mainViewController viewWillAppear:YES];
[introViewController viewWillDisappear:YES];
[introView removeFromSuperview];
[self.view addSubview:mainView];
[self.view insertSubview:menuButton aboveSubview:mainViewController.view];
[introViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
Once again,
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试实现
- (void) viewDidAppear:(BOOL)animated
方法来显示警报视图。每次将视图控制器的视图添加到窗口时都会调用此函数。这是文档
Try implementing the
- (void) viewDidAppear:(BOOL)animated
method to display the alert view. This will get called every time a view controller's view is added to a window.Here's the docs