set a delegate for UIWebView

萝らか妹 提交于 2019-11-30 08:49:56
Matthew Frederick

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

}

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.

Edit

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>

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

Edit 2

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;

This tells the UIWebView where it should send messages.

Follow the screen shot below

after connecting inYourViewController.h

@interface inYourViewController : UIViewController<UIWebViewDelegate>

now you are ready to implement the delegate methods in inYourViewController.m file.

or

you can do the same thing from code.

After connecting the webView with view controller via IBOutlet,In inYourViewController.m file's viewDidLoad Method write

self.yourWebView.delegate=self

In inYourViewController.h

@interface inYourViewController : UIViewController<UIWebViewDelegate>

Now you are ready to implement the delegate method of webView.Thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!