user391204
user391204

Reputation: 1

iPhone SDK UIWebView with Interface Builder

I have trouble accomplishing something that sounds very simple. Using Interface Builder, I created a UIWebView object. Next, I created a new controller - HomeViewController and assigned it to the WebView under "NIB Name" property. Next I need to load a web site (let's say http://google.com) into that WebView when user accesses that view. I am not able to find any examples on how to actually accomplish this. Please provide a code example. Sorry about the newbie question. I did RTFM, but no luck.

Upvotes: 0

Views: 2641

Answers (2)

Heli0s
Heli0s

Reputation: 119

The .h file:

@interface WebViewController : UIViewController {
    IBOutlet UIWebView *webView;
}

@property (nonatomic, retain) UIWebView *webView;

@end

The .m file:

#import "WebViewController.h"

@implementation WebViewController

// Loads the url when the view loads
- (void)viewDidLoad {
    NSString *urlAddress = @"http://www.google.com";

    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];

    //URL Request Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    //Load the request in the UIWebView.
    [webView loadRequest:requestObj];
}

@end

Upvotes: 2

Reena
Reena

Reputation: 845

try this :

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]]; // webview - your Uiwebview object

Upvotes: 1

Related Questions