views:

25

answers:

1

I'm trying to get a UIWebView working with the following code:

NSString *urlAddress = [NSString stringWithFormat: @"http://www.wikipedia.org/wiki/%@",recipe.name];

recipe.name is the entity and property from the core data model

I used NSLog to test the 'recipe.name' and it is outputting correctly to the console

I tried this witho just a plain URL and it works fine: NSString *urlAddress = [NSString stringWithFormat: @"http://www.wikipedia.org/wiki/soup"];

thanks for any help.

+1  A: 
  1. Initialize your webview.
  2. Create an NSURL-object containing your url(using +[NSURL URLWithString:] for example).
  3. Create an NSURLRequest-object with the created NSURL-object.
  4. load the NSURLRequest in your webView.
  5. Voila

    :)

Gubb
I had done that, and the code works like this:NSString *urlAddress = [NSString stringWithFormat: @"http://www.wikipedia.org/wiki/soup"]; NSURL *url = [NSURL URLWithString:urlAddress];NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];[webView loadRequest:requestObj];it doesn't work w/ the recipe.name object:NSString *urlAddress = [NSString stringWithFormat: @"http://www.wikipedia.org/wiki/%@",recipe.name]; NSURL *url = [NSURL URLWithString:urlAddress];NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj];
hanumanDev
U'll ned to encode the urlstring. as such:NSURL *url= [NSURL URLWithString: [urlAddress stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
Gubb
thanks so much for your replies.is that because there's a space in the 'recipe.name' - like "Club Sandwich" ?
hanumanDev
No worries! =)It's to avoid any character that might not work well in a URL, space being one of them.
Gubb
it's working now! that's a good bit of code to know.thanks again.
hanumanDev