Search code examples
objective-cbuttonback

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


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


Solution

  • 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];
    }