Search code examples
xcodewebviewios5

iOS5 Xcode: using a link within a web view to open a new view within app


Within one of my views, there is a webview that I load in a html page locally. Within this page I have a link (href) that when pressed it opens a view within the application and not a with in the webview/current view.

For example I have a button on this page that if pressed opens another view, is there any way I can do the same within a webview using a normal link?, the code I use for this button is below so is there away to get the href link in the web view link to similar code to open my new view up??

The link in the webview is a normal See view ???

    #import "anotherview.h"

    .....


    -(void)myhereflinkBtn:(id)sender{
anotherview *newviewPage = [[anotherviewhehffvv alloc] initWithNibName:nil bundle:nil];
[UIView transitionFromView:self.view 
                    toView: newviewPage view 
                    duration:1.0 
                   options: (UIViewAnimationCurveEaseInOut | UIViewAnimationOptionTransitionCurlUp)
                completion:^(BOOL finished){}];
    }

I hope this make sense.


Solution

  • Well with a bit of looking and a fresh face this morning I have manged to get 90% of what I am after working:

    Using this link as help CLICK HERE i have managed to get my xcode register my link press

       - (BOOL)theWebView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    
           if(navigationType == UIWebViewNavigationTypeLinkClicked) {
    
               NSLog(@"LINK CLICKED:");
    
    
               [webView stopLoading];
    
               return YES;
           }    
    
           return YES;
       }
    
      - (void)viewDidLoad
      {
          webView.delegate = self;
          [super viewDidLoad];
    
      }
    

    Within the header file I also then added < UIWebViewDelegate >