问题描述:

I am very new to iPad and was trying "Loading a web page using the Web View" - opening the google page!

I followed all the steps given in the box/tutorial but I am not able to view the page.

Step 1 : Added web view in the view window

Step 2 : decalre outlet for web view by adding following code

@interface WebiPadViewController : UIViewController {

IBOutlet UIWebView *webDisplayiPad;

}

@property(nonatomic,retain) UIWebView *webDisplayiPad;

Step 3 : Connect webview outlet to Web view using file manager

Step 4 : Create URl and request object using followng code:

 - (void)viewDidLoad {

NSString *urlAddress = @"http://www.google.com";

//Create a URL object.

NSURL *url = [NSURL URLWithString:urlAddress];

//URL Requst Object

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView.

[webDisplayiPad loadRequest:requestObj];

[super viewDidLoad];

}

Step 5 : Save and run the app to see google page.

But the Simulator shows only a white background!

网友答案:

Let me start by saying it is possible you simply haven't setup your ViewController class and View outlet property properly, as sergio describes, since that can also lead to a blank white background.

But I'm going to assume that it is your webDisplayiPad property that is not connected. I think this most likely since your "Step 3 : Connect webview outlet to Web view using file manager" seems a sketchy description at best.

To check your connection go to your WebiPadViewController.xib and right-click (cntrl-click) on the File's Owner icon. Under outlets there should be your webDisplayiPad listed with a circle to the right of it. If the circle is empty, and I suspect it is, drag from the circle to the UIWebView. The UIWebView will do a little flash to confirm. And your done.

Also the modern way of connecting IBOutlets is to put that keyword in the property definition and forget the ivar completely. For example:

@interface WebiPadViewController : UIViewController {

}
@property(nonatomic,retain) IBOutlet UIWebView *webDisplayiPad;

and in the .m file to do this:

@implementation WebiPadViewController
@synthesize webDisplayiPad = _webDisplayiPad;

The synthesize will create the backing variable for you and the _ character will help you keep them straight.

If you were to change to this way your loadRequest call would look like one of the following two:

[_webDisplayiPad loadRequest:requestObj]; // Calls through ivar
[self.webDisplayiPad loadRequest:requestObj]; // Calls through accessor method
网友答案:

Don't forget in you implementation:

@synthesize webDisplayiPad = _webDisplayiPad;
网友答案:

I think You have to load HTML into a UIWebView,

Please see this, I am sure this will help you, UIWebView Link

网友答案:

I guess that you got some problems with your Nib/Xib connections.

Please, check the following:

  1. your nib's file's owner class is set to be WebiPadViewController;

  2. your controller's view outlet is connected to the web view.

网友答案:

Set delegate. web page loads only when u set the delegate.

other wise it will be an empty page

相关阅读:
Top