开发者

iPhone SDK UIWebView with Interface Builder

开发者 https://www.devze.com 2023-01-07 10:04 出处:网络
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 WebV

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. N开发者_开发百科ext 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.


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


try this :

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号