Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to load a URL in WebView in iOS?

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 272
    Comment on it

    Hi guys,

    Today we'll learn how to load a URL in a WebView in iPhone.

    1. Go to Story-Board & drag Web view in your View Controller in which you want to open that URL or web address.
    2. Create its outlet in your View Controller as - IBOutlet UIWebView *myWebView;
    3. 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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: