为UIWebView设置委托 [英] set a delegate for UIWebView

查看:95
本文介绍了为UIWebView设置委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置 UIWebView 的委托以使用 webViewDidFinishLoad

How do I set a delegate for my UIWebView to use webViewDidFinishLoad?

推荐答案

在界面文件中表明您感兴趣:

In the interface file indicate that you're interested:

@interface SomethingController : UIViewController <UIWebViewDelegate> {



然后在您的实现中,您将添加该委托方法:


Then in your implementation you'll add that delegate method:

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    // Do whatever you want here

}

显然 SomethingController 应该是你的实际控制器和 UIViewController 是你实际实现的任何东西。

Obviously SomethingController should be your actual controller, and UIViewController is whatever you're actually implementing.

顺便说一句,这基本上就是你实现任何委托的方式。

This, by the way, is basically how you implement any delegate.

编辑

在基于窗口的应用中,假设您的UIWebView在您的app委托,您只需将其添加到委托列表中,用逗号分隔,如下所示:

In a window-based app, assuming your UIWebView is in your app delegate, you just add it to the list of delegates, separated by commas, like this:

@interface YourAppDelegate : NSObject <UIApplicationDelegate, UIWebViewDelegate>

您将在应用代表的实施中包含 webViewDidFinishLoad

You'll include your webViewDidFinishLoad in the app delegate's implementation.

编辑2

最后,您需要将UIWebView连接到控制器。通常在UIViewController的 viewDidLoad 方法中执行此操作,使用如下行:

Finally, you'll need to connect your UIWebView to your controller. It's common to do this in the viewDidLoad method of a UIViewController, with a line like this:

self.yourWebView.delegate = self;

这告诉UIWebView应该在哪里发送消息。

This tells the UIWebView where it should send messages.

这篇关于为UIWebView设置委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆