Skip to content

Commit

Permalink
Merge pull request #160 from TransitApp/feature/modal-done-button-del…
Browse files Browse the repository at this point in the history
…egate-callback

Add done button delegate callback to web controller.
  • Loading branch information
gdorion authored Sep 22, 2017
2 parents 9abad6b + 9baa86a commit d9ea847
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion SVWebViewController/SVModalWebViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@

#import <UIKit/UIKit.h>

@class SVModalWebViewController;

@protocol SVModalWebViewController <UIWebViewDelegate>

@optional
- (void)controllerDidPressDoneButton:(SVModalWebViewController *)controller;

@end

@interface SVModalWebViewController : UINavigationController

- (instancetype)initWithAddress:(NSString*)urlString;
- (instancetype)initWithURL:(NSURL *)URL;
- (instancetype)initWithURLRequest:(NSURLRequest *)request;

@property (nonatomic, strong) UIColor *barsTintColor;
@property (nonatomic, weak) id<UIWebViewDelegate> webViewDelegate;
@property (nonatomic, weak) id<SVModalWebViewController> webViewDelegate;

@end
10 changes: 9 additions & 1 deletion SVWebViewController/SVModalWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (instancetype)initWithURLRequest:(NSURLRequest *)request {
self.webViewController = [[SVWebViewController alloc] initWithURLRequest:request];
if (self = [super initWithRootViewController:self.webViewController]) {
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self.webViewController
target:self
action:@selector(doneButtonTapped:)];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
Expand Down Expand Up @@ -67,4 +67,12 @@ - (void)setWebViewDelegate:(id<UIWebViewDelegate>)webViewDelegate {
return self.webViewController.delegate;
}

- (void)doneButtonTapped:(id)sender {
[self.webViewController doneButtonTapped:sender];

if ([self.webViewDelegate respondsToSelector:@selector(controllerDidPressDoneButton:)]) {
[self.webViewDelegate controllerDidPressDoneButton:self];
}
}

@end

0 comments on commit d9ea847

Please sign in to comment.