iPhone - webViewDidFinishLoad 未调用
我有一个简单的 IB 视图,其中仅包含一个 UIWebView 和一个 UIButton。
webView 被保留,连接,而不是 nil,委托属性 os 也被连接,控制器是 UIWebViewDelegate
兼容并在 .h.
在 ViewDidLoad 中,我使用 [self.webView loadHTMLString:htmlContent baseURL:nil]
;
内容加载,但 webViewDidFinishLoad
永远不会触发,didFailLoadWithError
和 webViewDidStartLoad
都不会触发。
我如何知道我的内容何时完成加载,因为它需要很短的时间,但仍然需要加载时间(并且我需要在显示期间执行一些操作,例如不显示按钮) ?
@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
编辑: 我已经删除了整个 XIB 并从 scrathc 构建了它:不再有问题。 IB有时很糟糕。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要在类中实现
UIWebViewDelegate
协议并设置self.webView = self
的委托属性。您需要为该类实现非可选委托方法,以及webViewDidFinishLoad
、didFailLoadWithError
和webViewDidStartLoad
方法。You need to implement the
UIWebViewDelegate
protocol in your class and set the delegate property ofself.webView = self
. You will need to implement non-optional delegate methods to the class, plus thewebViewDidFinishLoad
,didFailLoadWithError
andwebViewDidStartLoad
methods.我已经删除了整个 XIB 并从头开始重新构建它:不再有问题。 IB有时很糟糕。
I've deleted the whole XIB and built it again from scratch : no more problem. IB sucks sometimes.
只是一种黑暗中的刺伤。就上面的代码而言,您仍然没有将响应对象设置为 webView 委托,您已经设置了一个指向 webView 委托对象的指针,但是当 webView 去响应委托时,它仍然为零。
你可能应该有: self.webView.delegate = a;但即便如此,我也不知道这是否有效,因为我不知道 a 是什么,它是响应委托回调的对象吗?
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?
您必须在类中实现 UIWebViewDelegate 协议并设置 self.webView.delegate=self;
You have to implement the
UIWebViewDelegate
protocol in your class and setself.webView.delegate=self;