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

Thethuthinang

macrumors member
Original poster
Jan 3, 2011
39
0
I have a program with two classes: THSite and THController. The program is eventually supposed to search a web site and gather all internal and external links. This will be done recursively through the method "searchNode:" in THSite. However, I am not having success making a load request from within this method, which is called from THController. I have no problem making a load request from within awakeFromNib. This is weird, as the actual load request is the same in each case. "webView" is the outlet to the instance of WebView created in IB. Here is some code:

Code:
-(void)searchNode:(NSString*)url{
	[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://name.com/"]]];
	NSLog(@"hey"); //this is to check that the method was called
	
        // unrelated code commented out during trouble-shooting
}

-(void)awakeFromNib{
	[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://name.com/"]]];	
}

I tried each separately, of course. Any idea of what might be wrong?

Also, do you know of a way with Cocoa to access web data without loading it into a view?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Most likely searchNode: is called before awakeFromNib so the webView is still nil. You need to load the nib first, then call that method.

Also, do you know of a way with Cocoa to access web data without loading it into a view?

You can use NSURLConnection, but you should also be able to use WebView without actually putting it inside a window (just alloc/init it). It all depends on what you need.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.