Reputation: 175
I am building an iOS application that uses the SWRevealViewController to display slide-out menus.
In my slide out menu, I have a WebView which contains some links. When a user clicks the link, I want the SWRevealViewController to slide back (I can do that easy enough), and the URL opens in the MainViewController WebView (not so easy for me).
I want to make sure, if possible, that the URL doesn't change at all in the SWRevealViewController. Just starts the action to open the URL in MainViewController.
How can I achieve this?
Upvotes: 0
Views: 963
Reputation: 5121
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
to your view controller.In your header add the UIWebViewDelegate protocol
@interface MyViewController : UIViewController <UIWebViewDelegate>
In your viewDidLoad set the delegate (Assuming you have an @property for the webView with an IBOutlet set to the UIWebView)
self.webView.delegate = self;
Then add the delegate method for loading requests.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString* urlStr = [[request URL] absoluteString];
if(request == nil || [urlStr isEqualToString:@"http://YourInitialURL"])
{
return YES;
}
//Use this url to change the other web view in your main view controller
NSURL* url = [request URL];
return NO;
}
Upvotes: 1