0

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
  • Any further information you can share with us - is your app crashing? is the webview not loading the URL at all and remaining blank? Are you also able to share the URL you're attempting to load? Commented Apr 20, 2010 at 21:37

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.