title: iOS UIWebView Restriction
body: <p>I'm trying to do a <code>UIWebView</code>, but not allowing the user to visit other part of the given URL. Something like they could only go specific pages where i allow them to go, and not others. </p>
  
  <p>I'm not too sure about the <code>- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType</code> method, so I may have made a mistake there. The problem now is that if I enable this method, I am loaded into the <code>webpage</code> but am unable to browse. Not even the section i allow.</p>
  
  <p>I would like to know if 1)Am I missing out any important code?, 2)Am I missing anything in the code, or why is my code wrong?</p>
  
  <p>Am new to Xcode, so I will require all the guidance that you guys can give/teach me. Below is my code from the view controller. </p>
  
  <p>EDIT1: Is there any prebuilt method by Xcode, or do I have to create my own method, such that when they are browsing the <code>UIWebView</code>, and when they click on another link, if its something other than what I specify, the request get rejected? Is it possible to create a  method such that it will constantly check the absolute url and if it change to something else other than what i specify, it will return to my specified url?</p>
  
  <p>in my.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface ViewController : UIViewController&lt;UIWebViewDelegate&gt;
  
  {
      IBOutlet UIWebView *webView;
  }
  
  @property (nonatomic, retain)  UIWebView *webView;  
  
  @end
  </code></pre>
  
  <p>in my .m</p>
  
  <pre><code>#import "ViewController.h"
  
  @interface ViewController ()
  
  @end
  
  @implementation ViewController
  @synthesize webView;
  
  - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  {
      NSString *currentURL = [[request URL]absoluteString];
      NSRange range1 = [currentURL rangeOfString:@"news"];
      NSRange range2 = [currentURL rangeOfString:@"pdf"];
  
  
  
      if (range1.location ==NSNotFound){
          currentURL = @"http://www.imc.jhmi.edu/news.html";
          [webView reload];
          return YES;
      }else if (range2.location ==NSNotFound){
          currentURL = @"http://www.imc.jhmi.edu/news.html";
          [webView reload];
          return YES;
      }
      return NO;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
      webView.scalesPageToFit=YES;
      webView.delegate = self;
  
      NSString *urlAddress = @"http://www.imc.jhmi.edu/news.html";
      NSURL *url =[NSURL URLWithString:urlAddress];
      NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
      [webView loadRequest:requestObj];
  
  }
  </code></pre>