Load Request

Discussion in 'Mac Programming' started by Thethuthinang, Mar 1, 2011.

  1. Thethuthinang macrumors member

    Jan 3, 2011
    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:

    	[[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
    	[[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?
  2. kainjow Moderator emeritus


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

    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.

Share This Page