0
votes

I have an array of UIViewControllers that I display in my Root View Controller of a UINavigationController... I have an issue with one of my controllers that I push on the stack. It needs to present a UIImagePickerController each time viewDidLoad, however only does so the first push. To get around this I implement UINavigationControllerDelegate in my Root View Controller:

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

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

The problem is it calls these messages twice the first push... otherwise would be great. What am I missing?

1

1 Answers

0
votes

You probably want to show the UIImagePickerController in viewDidAppear: instead of viewDidLoad:. Since you are keeping your view controllers in an array, they are only instantiated once therefore viewDidLoad: will most likely only be called once on each view controller. viewDidAppear: will be called every time the view controller is pushed or presented.

If your app got into a low memory situation it is possible that viewDidUnload: would be called at some point leading to viewDidLoad: being called again at some later point but you cannot rely on this at all.