Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,
This is a very newby question, but can someone look at this code and tell me why it isn't working?

Code:
[myWebView loadRequest:@"google.com"];


Thanks
 
The documentation states that the parameter to loadRequest must be a NSURLRequest object. You are passing a NSString. You must create a NSURLRequest object representing the URL you want to load. I would suggest using requestWithURL: which takes a NSURL (again not a NSString). You can create a NSURL from a NSString using URLWithString:.

Note that the compiler/Objective-C/Cocoa will not magically turn objects into the correct type for you: this is not AppleScript. You must pass the correct type of object.
 
Re:

Here is my new code but it still is not working:

Code:
[ myWebView loadRequest:[URLWithString:@"http://www.google.com"]];

It says URLWithString is not declared. I have Webkit imported, but it's just not working.
 
It's very clear you didn't understand what I typed. Or even Objective-C in general (as if you did you'd not have done that). URLWithString is a class-method of NSURL. If used correctly it'll return a NSURL. Which you then use to create the NSURLRequest object.

I suggest you take a few steps back, stop trying to write code and learn the language and how to use the documentation links I provided.
 
Figured it out. Here is the code I used for anyone who wants to learn from it:
Code:
[[myWebView mainFrame]loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
 
Last edited:
Figured it out. Here is the code I used for anyone who wants to learn from it:
Code:
[[myWebView mainFrame]loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];

Or more simply

Code:
[myWebView setMainFrameURL:@"http://www.google.com"];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.