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];
[introVi开发者_如何学编程ewController 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
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
精彩评论