Popviewcontroller does not call viewWillappear

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]; // You can now release the itemsViewController here, // UINavigationController will retain it [hv release]; // Place navigation controller view in the window hierarchy [[self window] setRootViewController:navController]; [navController release]; // Override point for customization after application launch. [self.window makeKeyAndVisible]; return YES; } 

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.

+6
source share
3 answers

Make sure your navigation controller delegate is installed, and then use this function to call viewWillAppear in the class whose viewWillAppear you want to call:

 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [self viewWillAppear:animated]; } 
+9
source

I just got into the problem very much, and after some testing I found that calling popViewControllerAnimated: in the block (from the network response in AFNetworking) viewDidAppear is not called in the parent view. The solution that worked for me here was to call it in the main thread.

 dispatch_async(dispatch_get_main_queue(), ^{ // If not called on the main thread then the UI doesn't invoke the parent view viewDidAppear [self.navigationController popViewControllerAnimated:YES]; }); 
+4
source

I just ran into this problem, and the main reason for this problem is that I put self.navigationController.delegate = self in viewDidLoad. My solution is to put delegation in viewWillAppear:

 - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.navigationController.delegate = self; } 

After that, popViewController will click viewWillAppear.

0
source

Source: https://habr.com/ru/post/898125/