iPhone - webViewDidFinishLoad 未调用

发布于 2024-12-11 07:07:38 字数 949 浏览 0 评论 0原文

我有一个简单的 IB 视图,其中仅包含一个 UIWebView 和一个 UIButton。
webView 被保留,连接,而不是 nil,委托属性 os 也被连接,控制器是 UIWebViewDelegate 兼容并在 .h.
在 ViewDidLoad 中,我使用 [self.webView loadHTMLString:htmlContent baseURL:nil];

内容加载,但 webViewDidFinishLoad 永远不会触发,didFailLoadWithErrorwebViewDidStartLoad 都不会触发。

我如何知道我的内容何时完成加载,因为它需要很短的时间,但仍然需要加载时间(并且我需要在显示期间执行一些操作,例如不显示按钮) ?

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

木格 2024-12-18 07:07:38

您需要在类中实现UIWebViewDelegate协议并设置self.webView = self的委托属性。您需要为该类实现非可选委托方法,以及 webViewDidFinishLoaddidFailLoadWithErrorwebViewDidStartLoad 方法。

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.

那片花海 2024-12-18 07:07:38

我已经删除了整个 XIB 并从头开始重新构建它:不再有问题。 IB有时很糟糕。

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

孤独患者 2024-12-18 07:07:38

只是一种黑暗中的刺伤。就上面的代码而言,您仍然没有将响应对象设置为 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?

表情可笑 2024-12-18 07:07:38

您必须在类中实现 UIWebViewDelegate 协议并设置 self.webView.delegate=self;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文