I have a WebView that I need to ask to load a website from a different class.Therefore I implemented the following function:
-(void)performResearch:(NSString *)aString {
NSLog(@"Received Request!");
[[researcher mainFrame]
loadRequest:[NSURLRequest
requestWithURL:[NSURL URLWithString:aString]]];
}
In my other class, I call the function like this:
Researcher *res = [[Researcher alloc] init];
[res performResearch:@"http://www.twitter.com"];
[res release];
I get no compiler errors and the NSLog does indeed get called, however the WebView doesn’t load the webpage. No errors in the Log either.I’m puzzled.
Could anyone tell me what’s wrong?
You don’t show where
researcheris declared, but it looks like a normal instance variable. Where does the value come from?If it comes from outside the
Researcherclass, then it looks like it isnilbecause your other class is creating a newResearcherinstance but not providing theresearcherattribute.. If you pass messages tonilobjects, the message is ignored. That is why you don’t get an error. Try breaking the load request line out into several lines and log the values of the objects.EDIT:
Interface Builder sets the
UIWebViewattribute of one particular instance of theResearcherclass. To update that web view, you need to callperformResearchon the same instance. You cannot use a new instance because it won’t be connected to a web view at all.If possible, you should pass the original
Researcherobject to the new class and use that instead: