views:

132

answers:

1

I'm having trouble getting a UIWebView to load a URL that I'm sending to it. Before I get into my code I was wondering if URL has to start with "http://" or can it start with "www."?

I'm using an IBAction to push a UIView on to the stack:

(IBAction)goToWebView {

WebViewController *webController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]];

//set the strings
webController.webTitle = [self Title];

webController.webURL = [self website];

//Push the new view on the stack
[[self navigationController] pushViewController:webController animated:YES];
[webController release];
webController = nil;

}

Then here is my WebViewController.h file:

@interface WebViewController : UIViewController {

IBOutlet UIWebView *webView;
NSString *webTitle;
NSString *webURL;

}

@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) NSString *webTitle;
@property (nonatomic, retain) NSString *webURL; here

And my WebViewController.m file:

- (void)viewDidLoad {
[super viewDidLoad];

NSString *urlAddress = webURL;

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

}
+1  A: 

Your first step should be to include error-checking in the viewDidLoad code in your WebViewController class. There are at least three pointers that could potientially be nil that, were you to catch them at their point of failure, would give you big insights as to what might be going wrong with your page loading code.

From there, the contents of webURL should be examined (AFAIK it should start with "http://" or similar) as well as the proper instantiation of the webView at the end of viewDidLoad.

fbrereto