for the past couple of days I've been looking into UIWebViews and Delegates and I'm totally confused. I want to create a storyboard view controller which contains a web view. When a button is clicked in the web view I want to fire some code in the view controller as per the answer to this:
How to invoke Objective C method from Javascript and send back data to Javascript in iOS?
However I'm confused as to how to set up my delegate (I'm confused as to what even a delegate is to be honest, is it the webview in relation to the viewcontroller?). I've been reading and watching some tutorials but I don't really understand the process and I don't think I'm doing it right. Here's what I have so far.
MyViewController.h
#import <UIKit/UIKit.h>
@protocol MyViewControllerDelegate;
@interface MyViewController : UIViewController
@property (nonatomic, weak) id<MyViewControllerDelegate> delegate;
@property (strong, nonatomic) IBOutlet UIWebView *MyWebView;
@end
@protocol MyViewControllerDelegate <NSObject>
-(bool)myWebView:(UIWebView*)myWebView
shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType;
@end
MyViewController.m
#import "MyViewController.h"
@interface MyViewController ()
@end
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
[_MyWebView setDelegate:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewWillAppear:(BOOL)animated
{
}
@end
I'm not really sure where the implementation for:
-(bool)myWebView:(UIWebView*)myWebView
shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType;
should go.
If anyone could help it would be greatly appreciated.