1
votes

I am attempting to follow this example: http://howtomakeiphoneapps.com/uiwebview-tutorial/239/

I have added a UIWebView into my view (using Storyboard)... I added the IBOutlet to my .h controller file. (see image at: http://imgur.com/GfUmC). I added a delegate to the view controller like this:

#import <UIKit/UIKit.h>

@interface slWebViewController : UIViewController <UIWebViewDelegate> {
    IBOutlet UIWebView *slWebView;    
}

@end

Since I'm using XCode 4, I don't know how to set the UIWebView's delegate to the File Owner, which is why I think this is what I'm getting a black screen. I'm missing something, but I don't know what. At this point, I would really, really appreciate any help I can get solving this...

1

1 Answers

1
votes

In your Storyboard, right click (or ctrl-click) and drag from your UIWebView to the File's Owner on the left side, and choose "delegate".

Alternatively, select the webView (as in your image). Note the top outlet, "delegate". Drag from there to the File's Owner.

Or you can code it. In viewDidLoad, type "self.sIWebView.delegate = self;"

All of this is assuming that you have your URL request right. In case you don't, here's an example:

NSURL * url = [NSURL URLWithString:@"http://google.com"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url  
                                                           cachePolicy: NSURLRequestReloadIgnoringCacheData    
                                                       timeoutInterval: 10];
    [sIWebView loadRequest:request];

EDIT: If you are presenting the webView modally, add this code to the view controller that segues to your webview: -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([segue.identifier isEqualToString:@"SegueIdentifier"]) { WebViewController *webView = segue.destinationViewController; webView.delegate = self; } } You'll need to add an identifier to your segue. Just click on the segue itself, go to the third tab from the right, and type in an identifier.

UPDATE: I've isolated the problem to the webViewConroller.m file. Everything is connected properly. If I place the loadRequest code in the viewController at viewDidLoad, I see Google. If I place the loadRequest code in the "webViewController", and mark the ViewContoller as a custom class of webViewController, I get the black screen. I'm wondering if there isn't a better way to get the UIWebView to display content? I really don't need a controller for the webView, just when the segue for that cell is tapped, display the contents of the UIWebView... not sure I can do it with XCode...