Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added UIWebViewDelegate passthrough

  • Loading branch information...
commit 129e9aa9608c6e09c22b42a9a0775b6a232cb0dd 1 parent 4570705
@jinthagerman jinthagerman authored
View
1  SVWebViewController/SVModalWebViewController.h
@@ -28,5 +28,6 @@ typedef NSUInteger SVWebViewControllerAvailableActions;
@property (nonatomic, strong) UIColor *barsTintColor;
@property (nonatomic, strong) UIImage *barsBackgroundImage;
@property (nonatomic, readwrite) SVWebViewControllerAvailableActions availableActions;
+@property (nonatomic, weak) id<UIWebViewDelegate> webViewDelegate;
@end
View
12 SVWebViewController/SVModalWebViewController.m
@@ -46,4 +46,16 @@ - (void)setAvailableActions:(SVWebViewControllerAvailableActions)newAvailableAct
self.webViewController.availableActions = newAvailableActions;
}
+- (SVWebViewControllerAvailableActions)availableActions {
+ return self.webViewController.availableActions;
+}
+
+- (void)setWebViewDelegate:(id<UIWebViewDelegate>)webViewDelegate {
+ self.webViewController.delegate = webViewDelegate;
+}
+
+- (id<UIWebViewDelegate>)webViewDelegate {
+ return self.webViewController.delegate;
+}
+
@end
View
1  SVWebViewController/SVWebViewController.h
@@ -16,5 +16,6 @@
- (id)initWithURL:(NSURL*)URL;
@property (nonatomic, readwrite) SVWebViewControllerAvailableActions availableActions;
+@property (nonatomic, weak) id<UIWebViewDelegate> delegate;
@end
View
32 SVWebViewController/SVWebViewController.m
@@ -114,6 +114,21 @@ - (UIActionSheet *)pageActionSheet {
return pageActionSheet;
}
+struct {
+ unsigned didStartLoad : 1;
+ unsigned didFinishLoad : 1;
+ unsigned didFailLoadWithError : 1;
+ unsigned shouldStartLoad : 1;
+} _delegateHas;
+
+- (void)setDelegate:(id<UIWebViewDelegate>)delegate {
+ _delegate = delegate;
+ _delegateHas.didStartLoad = [_delegate respondsToSelector:@selector(webViewDidStartLoad:)];
+ _delegateHas.didFinishLoad = [_delegate respondsToSelector:@selector(webViewDidFinishLoad:)];
+ _delegateHas.didFailLoadWithError = [_delegate respondsToSelector:@selector(webView:didFailLoadWithError:)];
+ _delegateHas.shouldStartLoad = [_delegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)];
+}
+
#pragma mark - Initialization
- (id)initWithAddress:(NSString *)urlString {
@@ -285,19 +300,36 @@ - (void)updateToolbarItems {
- (void)webViewDidStartLoad:(UIWebView *)webView {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self updateToolbarItems];
+
+ if (_delegateHas.didStartLoad) {
+ [self.delegate webViewDidStartLoad:webView];
+ }
}
+- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
+ if (_delegateHas.shouldStartLoad) {
+ [self.delegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
+ }
+}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
self.navigationItem.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
[self updateToolbarItems];
+
+ if (_delegateHas.didFinishLoad) {
+ [self.delegate webViewDidFinishLoad:webView];
+ }
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[self updateToolbarItems];
+
+ if (_delegateHas.didFailLoadWithError) {
+ [self.delegate webView:webView didFailLoadWithError:error];
+ }
}
#pragma mark - Target actions
Please sign in to comment.
Something went wrong with that request. Please try again.