Push the viewController containing webview to the NavigationController, and then
If the screen transition in the webview is stuck, I want the back button to be back in the webview and back to the original screen if it disappears
An easy way is to hide the buttons and make your own.
- (void) viewDidLoad{ superviewDidLoad; webView = [[UIWebView alloc] initWithFrame:self.view.frame]; [webView loadRequest: [NSURLRequestRequestWithURL: [NSURLURLWithString:@"https://www.google.co.jp/"]]]; [self.view addSubview:webView]; // Hide [self.navigationItem setHidesBackButton:YES animated:YES]; UIBarButtonItem*back=[[UIBarButtonItem alloc] initWithTitle: @"back" style: UIBarButtonItemStylePlain target:selfaction:@selector(didBackButtonTap:); [self.navigationItem setLeftBarButtonItem:back]; } -(void) didBackButtonTap:(UIBarButtonItem*)item { if(webView.canGoBack){ webView goBack; } else { [self.navigationController popViewControllerAnimated: YES]; } }
You need to hook the back button to use it as it is.
I had a helpful question about how to do it.
UINavigationController: How to cancel the back button event?
© 2024 OneMinuteCode. All rights reserved.