Skip to content

Instantly share code, notes, and snippets.

@dothework
Created May 20, 2015 20:40
Show Gist options
  • Save dothework/ebd6904c206420bd4ee4 to your computer and use it in GitHub Desktop.
Save dothework/ebd6904c206420bd4ee4 to your computer and use it in GitHub Desktop.
Back Button Code for Checkpoint #32
- (void) updateBackButton {
if ([self.webView canGoBack]) {
if (!self.navigationItem.leftBarButtonItem) {
[self.navigationItem setHidesBackButton:YES animated:NO];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"< Login" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClicked)];
self.navigationItem.leftBarButtonItem = backButton;
}
} else {
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
}
}
- (void) backButtonClicked {
if ([self.webView canGoBack]) {
[self.webView goBack];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self updateBackButton];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment