0

I have a webview that loads a page which allows the user to upload pictures. When the user chooses the option to "take photo", the app crashes with the following warning.

Warning: Attempt to present <UIImagePickerController: 0x1563d8000> on <UINavigationController: 0x156b4c400> whose view is not in the window hierarchy!

Here is the code that is being used to load the webview

WebViewController *webViewController = [[WebViewController alloc] initWithUrlString:urlString];
[viewController showViewControllerFullScreen:webViewController];

- (void)showViewControllerFullScreen:(UIViewController *)viewController {
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    [self.view.window.rootViewController presentViewController:navigationController animated:YES completion:nil];
}

Why is the UINavigation Controller not part of the window hierarchy when it is being used to present the web view?

Virendra Nagda
  • 673
  • 5
  • 9
user4321945
  • 93
  • 2
  • 9

1 Answers1

0

Please set the below line

  self.window.rootViewController = navigationController;

Reference

UIImagePickerController on UINavigationController whose view is not in the window hierarchy

iOS: Warning “attempt to present ViewController whose view is not in the window hierarchy”

Community
  • 1
  • 1
user3182143
  • 9,459
  • 3
  • 32
  • 39
  • 1
    Thanks for your suggestion - that helped but has landed me into another issue. I am using a framework from an existing application that adds a button to the view on which the webview is loaded. The button is used to close the webview and return back to the app. After making your suggested change, the button fails to dismiss the webview page. The button action implements the following : - `(void)onCancelButton:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; }` – user4321945 Dec 12 '15 at 00:20
  • Where did you call this method?Did you put break point and did you check whether the button action method is called? – user3182143 Dec 12 '15 at 04:03
  • Did you call these lines in didFinishLaunchingWithOptions of appDelegate.m? – user3182143 Dec 12 '15 at 04:09
  • If my answer is helpful for you,tick and up vote my answer.Because others can get the solution through your question. – user3182143 Dec 12 '15 at 04:26
  • This method is called in the WebViewController.m. The button action method does get called but it does not dismiss the view controller. The dismissViewControllerAnimated method does: `- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion { [self willChangeValueForKey:NSStringFromSelector(@selector(presentedViewController))]; [super dismissViewControllerAnimated:flag completion:^{ if (completion != nil) { completion(); } [self didChangeValueForKey:NSStringFromSelector(@selector(presentedViewController))]; }]; }` – user4321945 Dec 12 '15 at 05:40
  • It will not be possible to send you the code since it is part of a proprietary app and moreover the codebase is very large. What I am trying is adding on a very small functionality to load a webview to the existing app. – user4321945 Dec 12 '15 at 18:10