I use the following code to display the previous view when the user clicks a button
[self.navigationController popViewControllerAnimated:YES]
In the previous view, I rewrite viewWillAppear to initialize several things. However, it seems that viewWillAppear is not being called. I set the NSLog to viewDidload, viewWillAppear, viewDidAppear and only viewDidAppear is called. Is this normal behavior? If so, which event should be redefined so that I can perform my initialization? Thanks.
As requested by -viewWillAppear for the previous view
- (void)viewWillAppear:(BOOL)animated{ NSLog(@"ViewWillAppear"); //[[GameStore defaultStore] resetGame]; [self setHangmanImage]; NSLog([[[GameStore defaultStore] selectedList] label]); [labelListName setText:[NSString stringWithFormat:@"List Name: %@", [[[GameStore defaultStore] selectedList] label]]]; [labelCurrentIndex setHidden:YES]; [labelCurrentWord setHidden:YES]; [[self navigationController] setNavigationBarHidden:NO]; [FlurryAnalytics logEvent:@"GameViewController - viewWillAppear"]; [self getNewQuestion]; NSLog(@"ViewWillAppear finish"); [super viewWillAppear:YES]; }
I configure the UINavigationalController in the application delegate using the following code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { HomeViewController *hv = [[HomeViewController alloc] init]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:hv];
UPDATE
I donβt know what happened, but last night, trying to run the application again in the simulator and still having this problem, I decided to save everything and close my computer because it was late.
This morning I turned on the computer again, opening xcode, clearing the project, built and started it, and the problem is solved and -viewWillAppear is called. I did not change anything and worked. I added NSLog to -willShowView and it was not called. I don't know why viewWillAppear is called all the time.