-(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];
Within performResearch:
, the object you sent the performResearch:
message to in the latter code is self
. researcher
is some other variable; you are talking to a different object that is probably not this Researcher.
In your comment on Colin Gislason's answer, you say that researcher
is not a Researcher, but is a WebView. You would do well to correct this inaccurate choice of variable name.
Once you've renamed the variable to something more accurate, like webView
, you then need to make sure there is something in it. Simply having a variable is of no help; you need to have a pointer to an object in the variable. Otherwise, the pointer in the variable is nil
, and messages to nil
do nothing at all. They do not crash, they do not fail, they do not succeed, they do not break—execution continues as if nothing happened, because it did.
You say that the variable is an IBOutlet; this implies that you mean to hook up the outlet in IB. One possible cause of your problem is that you forgot to do that, which would explain the variable containing nil
. Make sure it's connected in IB.
The other possible cause of your problem is that this nib has not been loaded. If the Researcher object owns the nib, then it is generally its responsibility to load it, which means you need to do that. If some other object is loading a nib with both a Researcher and a WebView in it, then your creation of another Researcher object in the latter code snippet is wrong; this second Researcher object has no relation to the one in the nib, nor has it a WebView from any source. In this latter case, you would have to cut out the creation of a Researcher object, and use the one in the nib.
That last solution may require adding an outlet to the object whose class hosts the second code snippet. I disapprove of that solution. It's difficult to say what you should do because I'm not sure where Researcher objects fit in the MVC triumvirate. I suspect you need to think some more about which category it's in; I think that it should be a Controller, and that you will need to do some refactoring to re-establish the boundaries you should have between powers.
Failure to uphold MVC in your app generally results in Cocoa being harder to use than it normally is.