title: Disable back/forward button in web browser
body: <p>In my app, I have a <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html" rel="nofollow noreferrer">UIWebView</a>. Beneath it, I have a toolbar with the back and forward buttons to control the browser. How do I disable the back button when the user is on the initial page and disable the forward button when the user is on the most recent page? Looking at the <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html" rel="nofollow noreferrer">UIWebViewDelegate</a> protocol, I don't see any callbacks that tell me the position of the user in their browser history.</p>
  
  <p>It should look like Safari's toolbar:</p>
  
  <p><img src="https://i.stack.imgur.com/Plz5N.jpg" alt="enter image description here"></p>
  
  <p><strong>Edit:</strong> I figured out the detection part, but I can't figure out the disabling part. My buttons always remain at full opacity and are tappable even when <code>NSLog</code> prints out <code>0</code> for <code>canGoBack</code> or <code>canGoForward</code>.</p>
  
  <p>.h</p>
  
  <pre><code>@interface VeetleViewController : UIViewController &lt;UIWebViewDelegate&gt; {
      UIWebView* webView;
      UIBarButtonItem* buttonBack;
      UIBarButtonItem* buttonForward;
      UIActivityIndicatorView* activityIndicator;
  }
  
  - (void)activityIndicatorStop;
  
  @property (nonatomic, retain) IBOutlet UIWebView* webView;
  @property (nonatomic, retain) IBOutlet UIBarButtonItem* buttonBack;
  @property (nonatomic, retain) IBOutlet UIBarButtonItem* buttonForward;
  @property (nonatomic, retain) UIActivityIndicatorView* activityIndicator;
  
  @end
  </code></pre>
  
  <p>.m</p>
  
  <pre><code>- (void)webViewDidStartLoad:(UIWebView *)webView
  {
      NSLog(@"canGoBack:%d canGoForward:%d", self.webView.canGoBack, self.webView.canGoForward); 
  
      [self.activityIndicator startAnimating];
  
      if (self.webView.canGoBack) {
          self.buttonBack.enabled = YES;
      } else {
          self.buttonBack.enabled = NO;
      }
  
      if (self.webView.canGoForward) {
          self.buttonForward.enabled = YES;
      } else {
          self.buttonForward.enabled = NO;
      }
  }
  </code></pre>