1

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 Answer 1

1
+100

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...

Sign up to request clarification or add additional context in comments.

21 Comments

It didn't change a thing! I've uploaded my code and a screen shot of what I'm seeing. Hopefully you can see what I did wrong. :D Code is here (there are 3 views) imgur.com/4GnfE,k667K,sQGVp
Copy this and paste it in your -viewDidLoad: NSURL * url = [NSURL URLWithString:@"http://google.com"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: 10]; [slWebView loadRequest:request]; Then load it and see what happens. You don't have any code telling the webView what to display.
Nothing happens... it's still black. FYI, in my app, there are two segues which get activated depending on which was chosen... they display different html, one from a file, the other program generated html. I'm wondering if I should delete the UIWebView that is in the UIViewController and start again from the beginning?
I think I've got it... give me a few minutes to try it on my app (I made a test app and it worked!) brb
What type of segue is it? 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. This should solve your problem.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.