I'm developing an app with an UINavigatorController. I am using the method viewDidAppear in the second pushed viewController to find information in an external server.
Well. While in iOS5 worked fine at the beginning, I realized that viewDidAppear was not being called in iOS4.3 so I put this code in the root:
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[viewController viewDidAppear:animated];
}
Thereafter, the app started to work properly in iOS4.3. However, in iOS5 didn't because it's calling twice viewDidAppear (the one which was being called at first and the one from the navigationController:didShowViewController:animated:
)
What should I do to have only called once viewDidAppear?
Thank you very much
viewDidAppear callback can be called multiple times in a single presentation.
If both these methods are called, what's the difference between the two? viewDidLoad() is only called once, when the view is loaded from a . storyboard file. viewWillAppear(_:) is called every time the view appears. In this simple app, that means it is only called once.
viewDidAppear is called once you see the loaded view on screen. It is called after view appeared. ViewDidAppear is called everytime when you see the view after it is loaded.
The only real solution I see (or rather workaround for iOS 4.x) if you set some kind of state in your viewWillAppear-call and check whether it's been set or not in subsequent calls, e.g.
-(void)viewWillAppear:(BOOL)animated {
if (!viewWillAppearCalled) {
viewWillAppearCalled = YES;
/* do stuff */
}
}
Then you could safely call it manually for compatibility with iOS 4.x .
Same thing can be done for viewDidAppear, viewWillDisappear and viewDidDisappear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With