I have a project with a web browser inside. How do I make a back button in the navigation bar for the browser?

StackOverflow https://stackoverflow.com/questions/22440436

  •  15-06-2023
  •  | 
  •  

Pregunta

I need the back button to make the browser go back, instead of navigate through the different app views.

¿Fue útil?

Solución

I assume the "web browser" is a UIWebView? If so, the -goBack method will go back to the prior web page.

You shouldn't use the navigation bar to do this, as the navigation bar is primarily intended for navigating the views/screens of the app. Instead, create a toolbar, put a "back button" in the toolbar (perhaps a left-pointing arrow image, as that's fairly common for web browser "back"), and hook this button to the -goBack method.

You may not be able to hook the -goBack method directly to your button, as it's strictly not an IBAction. But that's easy enough to work around:

- (IBAction)doGoBack:(id)sender {
    [self.webview goBack];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top