Iphone 应用程序开发 - 如何重新加载(?)视图?

发布于 2024-08-21 08:27:13 字数 880 浏览 3 评论 0原文

好的,我正在开发 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街女流氓 2024-08-28 08:27:13

尝试实现 - (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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文