ViewDidAppear twice called iOS5

I am developing an application using the UINavigatorController. I use the viewDidAppear method in the second clicked viewController to search for information on an external server.

Well. Although it worked fine in iOS5 at the beginning, I realized that viewDidAppear is not called in iOS4.3, so I put this code in the root directory:

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { [viewController viewDidAppear:animated]; } 

After that, the application began to work correctly in iOS4.3. However, in iOS5, not because it called viewDidAppear twice (the one that was called first, but one from navigationController:didShowViewController:animated:

What if you only called viewDidAppear?

Many thanks

+6
source share
5 answers

Check which version of iOS the user is running with [[UIDevice currentDevice] systemVersion]; and in case 4.3, call the viewDidAppear method.

+1
source

The only real solution that I see (or rather, a workaround for iOS 4.x) is if you set some state in your viewWillAppear call and check if it was set or not in subsequent calls, for example.

 -(void)viewWillAppear:(BOOL)animated { if (!viewWillAppearCalled) { viewWillAppearCalled = YES; /* do stuff */ } } 

You can then safely call it manually for compatibility with iOS 4.x.

The same can be done for viewDidAppear, viewWillDisappear and viewDidDisappear.

+4
source

You probably have another problem (why viewDidAppear is not called in iOS 4).

However, I ran into inconsistencies between iOS 5 and iOS 4 in this regard, because I used a custom container view controller (neither UINavigationController nor UITabBarController). The fix for restoring compatibility with iOS 4 was to implement the following method in the container controller:

 - (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers { return NO; } 
+2
source

If it is called twice, and you could only make the call when you added the code to the root navigation, why not remove the code from viewDidAppear (the first one you made that worked on iOS5) and leave only one that worked like 4.3 so with 5?

0
source

You should not call viewDidAppear: manually, leave it before UIKit to call it for you. If you delete a manual call, it should be called only once.

-1
source

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


All Articles