问题
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