Monday, June 3, 2013

UIWebView canGoForward example in Objective C (iOS).


UIWebView canGoForward

A Boolean value indicating whether the receiver can move forward. (read-only)

@property(nonatomic, readonly, getter=canGoForward) BOOL canGoForward

Discussion of [UIWebView canGoForward]
If YES, able to move forward; otherwise, NO .

UIWebView canGoForward example.
- (void) webViewDidFinishLoad:(UIWebView *)webView {
    if ([resultsWebView canGoBack]) {
        [goBackButton setEnabled:YES];
    }
    else {
        [goBackButton setEnabled:NO];
    }
    if ([resultsWebView canGoForward]) {
        [goForwardButton setEnabled:YES];
    }
    else {
        [goForwardButton setEnabled:NO];
    }
}

Example of [UIWebView canGoForward].
- (void)webViewDidFinishLoad:(UIWebView *)webView {

    BOOL ableToGoBack = [webViewOutlet canGoBack];
    BOOL ableToGoForword = [webViewOutlet canGoForward];

    if (ableToGoBack == YES) {
        UIImage *goBackImageChange = [UIImage imageNamed:@"browserBack@2x.png"];
        [goback setBackgroundImage:goBackImageChange forState:UIControlStateNormal];
    } else {
        UIImage *goBackImageChange = [UIImage imageNamed:@"browserBackInactive@2x.png"];
        [goback setBackgroundImage:goBackImageChange forState:UIControlStateNormal];
    }
    if (ableToGoForword == YES) {
        UIImage *goForwordImageChange = [UIImage imageNamed:@"browserForward@2x.png"];
        [goforowrd setBackgroundImage:goForwordImageChange forState:UIControlStateNormal];
    }  else {
        UIImage *goForwordImageChange = [UIImage imageNamed:@"browserForwardInactive@2x.png"];
        [goforowrd setBackgroundImage:goForwordImageChange forState:UIControlStateNormal];
    }

    [activityIndicator stopAnimating];
    activityIndicator.hidden = YES;
}

UIWebView canGoForward example.
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
  // Enable or disable back
  [myBackButton setEnabled:[myWebView canGoBack]];

  // Enable or disable forward
  [myForwardButton setEnabled:[myWebView canGoForward]];

 }

End of UIWebView canGoForward example article.