Loading a webpage in UIWebView in Xcode 4.2 - how to properly connect IBOutlets and ensure that the webpage loads?

Most of the tutorials for implementing UIWebView in an iPhone app are based on older versions of Xcode. Here is an example: http://howtomakeiphoneapps.com/uiwebview-tutorial/239/

We have completed the steps described in this tutorial, but the steps don't quite go to Xcode 4.2

There is no concept of a file owner, for example, but there is a "storyboard".

Another question: how to link UIWebView with IBOutlet UIWebView?

When we add a UIWebView and connect it to the ViewController, all we see is a white screen. The webpage never loads.

Can anyone share some tips on loading a webpage using UIWebView for Xcode 4.2?

+8
ios objective-c iphone xcode ios4
source share
3 answers

If you are using a storyboard, the file owner still exists, but it is called View Controller. Therefore, to associate a UIWebView in a storyboard with a UIWebView output, you hold control, then click and drag a row from the view controller to the web view. All of this is in the "View Controller Scene" panel to the left of the storyboard.

Please note that when you first create your project from the Single View application template, there is no need to check the box "Use storyboard". You may find it easier to follow these old tutorials if you are not using a storyboard.

By the way, another important flag, only in the section "Using the storyboard", is "Use automatic reference counting". This is a great feature, but if you turned it on when you followed the tutorial you contacted with, you need to skip the part where it frees up the webView instance webView .

+8
source share

.h file

 @interface webViewViewController : UIViewController <UIWebViewDelegate> 

.m file

 UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 640.0)]; NSURL *URL = [NSURL URLWithString:@"http://google.com"]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:URL]; webView.delegate = self ; [webView loadRequest:requestObj]; [self.view addSubview:webView]; 

webview is the name of the IBOutlet that I created for UIWebView. To do and exit, just Contrl + drag and drop from the UIWebView to your H file between @interface and @end.

Hope this helps you.

+1
source share

Try creating a new class for web view code only. To create a new class, right-click or select "+" in the project folder in the left pane in Xcode. Select New File and create a new class that is a subclass of UIViewController. Leave both boxes unchecked. Then select the screen on which the web view will be displayed, and select the identity inspector in the panel on the right. Change the class to the name of the class you made earlier. Use all the code from the tutorial that you found, except for the part - (void) dealloc. Connect all the outputs to the user interface elements and you must do this. Answer this if you still have problems, I would be happy to help. Postscript Use storyboards.

0
source share

All Articles