iPhone - webViewDidFinishLoad not called

拜拜、爱过 提交于 2020-02-02 07:26:29

问题


I have a simple View into IB that contains just a UIWebView and a UIButton.
The webView is retained, connected, not nil, the delegate property os also connected, the Controller is UIWebViewDelegate compliant and set in the .h.
in ViewDidLoad, I use [self.webView loadHTMLString:htmlContent baseURL:nil];

The content loads, but webViewDidFinishLoad is never triggered, neither didFailLoadWithError, neither webViewDidStartLoad.

How can I know when my content has finished loading, as it take a short time, but still a time to load (and I need to do things during that time on display, for an example not showing the button) ?

@interface MyController : UIViewController <UIWebViewDelegate> {
    UIWebView* webView;
}

@property (nonatomic, retain) IBOutlet UIWebView* webView;

@end


@implementation MyController

@synthesize webView;

- (void)viewDidLoad
{
[super viewDidLoad];

constructing the htmlString

id a = self.webView.delegate; // for debug
[self.webView loadHTMLString:htmlContent baseURL:nil];
}

@end

EDIT : I've deleted the whole XIB and built it from scrathc : no more problem. IB sucks sometimes.


回答1:


You need to implement the UIWebViewDelegate protocol in your class and set the delegate property of self.webView = self. You will need to implement non-optional delegate methods to the class, plus the webViewDidFinishLoad, didFailLoadWithError and webViewDidStartLoad methods.




回答2:


I've deleted the whole XIB and built it again from scratch : no more problem. IB sucks sometimes.




回答3:


Just a sort of stab in the dark. As far as your code above is concerned, you still haven't set the responding object to the webView delegate, you have set a pointer to the webView delegate object but when the webView goes to respond to the delegate it will still be nil.

You should probably have: self.webView.delegate = a; but even then I don't know if that will work because I don't know what a is, is it the object that will respond to the delegate call backs?




回答4:


You have to implement the UIWebViewDelegate protocol in your class and set self.webView.delegate=self;



来源:https://stackoverflow.com/questions/7862962/iphone-webviewdidfinishload-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!