如何为我的 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 在您的应用委托中,您只需将其添加到委托列表中,用逗号分隔,如下所示:
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 设置委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!