John John - 1 year ago 153
iOS Question

Back Button on UIWebView

I'm trying to figure out how to create a back button that allows the user to go back one page. I read through Apple's Docs (which still go way over my head) and found out that I need to setup the

's. I have tried this, but for some reason it is not working. My
is named
, and I created and attached an outlet to my Back button, named
, and also tagged it as 1. Here is my code that I wrote in the View Controller:

// Back button:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {

[_backButton addTarget:_viewWeb

if ([_viewWeb canGoBack]) {

NSLog(@"Back button pressed.");
[_viewWeb goBack];

else return;

Does anyone know what I need to change / add to get this working?

Answer Source

actionSheet:clickedButtonAtIndex: is for UIActionSheet objects, not UIButton actions.

You should probably write an IBAction method that looks something like this:

- (IBAction)backButtonTapped:(id)sender {
   [_viewWeb goBack];

and connect it to the Touch Up Inside action from the button.

You can search for more info on IBAction but that's likely what you want

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download