i'm going to write an app including an UIWebView. So first I wanted to try it out by just simply loading an URL.
Hooked up to the code
@property(nonatomic,retain) IBOutlet UIWebView *webView;
viewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
if(!webView)
{
webView = [[UIWebView alloc]init];
}
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]]; }
also I implemented the didFailLoadWithError and webViewDidFinishLoad delegate methods. webViewDidFinishLoad is called and indicating that HTML has been loaded.
Problem is: Even though webViewDidFinishLoad is called, the UIWebView doesn't display the website. It's only showing white color. The scroll bars right and at the bottom are shown when the UIWebView is touched and dragged but not content is visible. Nowhere found anything. Seems quite strange..
EDIT This screenshot shows the connections of the xib:
If you hooked everything up in Interface Builder correctly, the following lines should not be needed:
if(!webView)
{
webView = [[UIWebView alloc]init];
}
webView.delegate = self;
Try removing them and see what happens. Also, put an NSLog(...)
in the webView:didFailLoadWithError:
callback and see if it is output.
I got it.. I used synthesize in the following way:
@synthesize webView = _webView;
So it was necessary to call the UIWebView in the following way:
[self.webView loadRequest:...];
New to this naming convention which is why i'm not used to necessity of self
Have you checked the File's Owner connect to the webView you declared?
Besides, webViewDidFinishLoad does not mean the HTML was loaded! Whatever the content is loaded successful, this method will be called.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.