I am trying to build a custom control based on a UIWebView and compile it into a library for reuse. Everything was working just fine when I had the code all together in a single test app but I'm having some trouble setting up a the delegate for the view for a library. Of note, the sample app used interface builder and thus the delegate was set via IB.
NewsView.h:
@interface NewsView : UIWebView {
NSObject<UIWebViewDelegate> *delegate;
}
@property (nonatomic, assign) IBOutlet NSObject<UIWebViewDelegate> *delegate;
In the implementation all of my initialization methods call a common method viewInit
NewsView.m
@implementation NewsView
@synthesize delegate;
- (void)viewInit {
self.delegate = [[NewsViewDelegate alloc] init];
}
If the user clicks on one of the headlines in the view I need the delegate to intercept clicks and launch Safari.
NewsViewDelegate.h
@interface NewsViewDelegate : NSObject <UIWebViewDelegate> {
}
NewsViewDelegate.m
// Intercept URL events
- (BOOL)webView:(UIWebView *)myWebView shouldStartLoadWithRequest:
(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(@"URL Changed");
// Check to see if this is a click event
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[[request URL] absoluteString]]];
return NO;
}
return YES;
}
Unfortunately shouldStartLoadWithRequest never gets called and so clicks are not being launched externally.
I'm sure I'm just missing something, any help would be greatly appreciated.
Thanks!