title: Navigate a WebView
body: <p>With a webview is it possible to set up a simple 'Back' button (either in a navigation bar or a top toolbar) that doesn't show the back button on the first URL of the WebView - and only appearing on a second URL to get back to the first?</p>
  
  <p>Unless I'm getting getting this wrong, in a lot of hybrid native/web apps such as News apps, you often see news articles in a table (HTML page rather than a 'programmed in xcode' table) which hyperlink to article detail pages (again, HTML rather than natively coded) - what I can't figure, is how the detail page (2nd URL in webview) displays with a 'back button' but the table (1st URL in webview) doesn't have the button showing in these type of apps?</p>
  
  <p>Currently, I have a webview as described, with a 'back' bar button item in a toolbar at the top of screen (outlet as 'cangoback' for WebView) but the button is visible right from the start when there's no page to 'go back' to - </p>
  
  <p>What I've got simply is:</p>
  
  <p>Webview - 1st URL, HTML table - 'back' button shows, but isn't active (of course)</p>
  
  <p>Webview - 2nd URL, HTML detail page - 'back' button shows, and can go back.</p>
  
  <p>How do you get it to only appear on 2nd URL, or be HIDDEN on 1st URL?</p>
  
  <p>Regards
  Randy</p>
  
  <p>EDIT (25th November)</p>
  
  <p>Here's my h:</p>
  
  <pre><code>    #import &lt;UIKit/UIKit.h&gt;
      #import "FilmnoirNavController.h"
  
  
      @interface FilmnoirViewController : UIViewController &lt;UIWebViewDelegate&gt; {
          IBOutlet UIWebView *webView;
          IBOutlet UIBarButtonItem *backButton;
  
      }
  
      @property (nonatomic, retain) UIWebView *webView;
      @property (nonatomic, retain) UIBarButtonItem *backButton;
  
  - (IBAction)backButtonClicked:(id)sender;
  
      @end
  </code></pre>
  
  <p>and here's my m:</p>
  
  <pre><code>#import "FilmnoirViewController.h"
  
  
  @implementation FilmnoirViewController
  
  @synthesize webView;
  @synthesize backButton;
  
  - (IBAction)backButtonClicked:(id)sender {
      [webView goBack];
  }
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
      if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
          // Initialization code
      }
      return self;
  }
  
  /*
   Implement loadView if you want to create a view hierarchy programmatically
   - (void)loadView {
   }
   */
  
  /*
   If you need to do additional setup after loading the view, override viewDidLoad. */
  - (void)viewDidLoad {
  
      NSString *urlAddress = @"http://www.filmsite.org/filmnoir.html";
  
      //Create a URL object.
      NSURL *url = [NSURL URLWithString:urlAddress];
  
      //URL Requst Object
      NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
  
      //Load the request in the UIWebView.
      [webView loadRequest:requestObj];
  }
  
  - (void)webViewDidFinishLoad {
      // Other stuff if necessary...
  
      // Could use hidden instead of enabled if you don't even want
      // the button to be visible
      backButton.enabled = (webView.canGoBack);
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      // Return YES for supported orientations
      return (interfaceOrientation == UIInterfaceOrientationPortrait);
  }
  
  - (void)didReceiveMemoryWarning {
      [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
      // Release anything that's not essential, such as cached data
  }
  
  - (void)dealloc {
      [webView release];
      [super dealloc];
  }
  
  @end  
  </code></pre>
  
  <p>My IB layout:</p>
  
  <pre><code>Filmnoir View Controller (Film noir)
  &gt; View
  &gt;&gt;Web View
  &gt;&gt;Tool Bar
  &gt;&gt;&gt;Bar Button Item (Back)
  </code></pre>
  
  <p>Thought I had it with something like this to hide the backButton:</p>
  
  <pre><code>- (void)webViewDidFinishLoad {
      BOOL ableToGoBack = [webView canGoBack];
  
      if (ableToGoBack == NO) {
          [backButton setHidden:YES];
      }
      else {
          [backButton setHidden:NO];
      }
  </code></pre>
  
  <p>but warning says a UIbarButton item may not respond to setHidden - and indeed it doesn't.</p>