Monday, June 3, 2013

UIWebView loadRequest example in Objective C (iOS).


UIWebView loadRequest

Connects to a given URL by initiating an asynchronous client request.

- (void)loadRequest:(NSURLRequest *)request

Parameters of [UIWebView loadRequest]
request
A URL request identifying the location of the content to load.

Discussion of [UIWebView loadRequest]
To stop this load, use the stopLoading method. To see whether the receiver is done loading the content, use the loading property.

UIWebView loadRequest example.
- (void)viewDidLoad {
  [super viewDidLoad];
webView.delegate = self;
  NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
  NSURLRequest *request = [NSURLRequest requestWithURL:url];
  [webView setScalesPageToFit:YES];        
  [self.webView loadRequest:request];              
}

Example of [UIWebView loadRequest].
NSString *urlAddress = @"http://www.google.com";

    //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];

UIWebView loadRequest example.
[activityIndicator startAnimating];

NSURL *url = [NSURL URLWithString:urlWeb];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[vue loadRequest:request];
vue.scalesPageToFit = YES;
And here is the protocol methods

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [activityIndicator stopAnimating];
}

End of UIWebView loadRequest example article.