Hi guys,
Today we'll learn how to load a URL in a WebView in iPhone.
- Go to Story-Board & drag Web view in your View Controller in which you want to open that URL or web address.
- Create its outlet in your View Controller as - IBOutlet UIWebView *myWebView;
- Set the delegates of your webview as - @interface YourViewController : UIViewController <UIWebViewDelegate> & myWebView.delegate = self;
Also include the following delegate methods-
-(void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"Load view");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"Finish View");
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"Error in loading: %@", [error description]);
}
Now we simply have to define the URL or the Web address which we want to load in our Web View as-
NSString *urlString = @"https://www.google.co.in";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:urlRequest];
Hope you understand..thanks for reading..
0 Comment(s)